ReactOS 0.4.16-dev-297-gc569aee
phys_lib.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PH_TMP_BUFFER   1
 
#define PH_VCB_IN_RETLEN   2
 
#define PH_LOCK_CACHE   0x10000000
 
#define PH_EX_WRITE   0x80000000
 
#define PH_IO_LOCKED   0x20000000
 
#define UDFReadSectors(Vcb, Translate, Lba, BCount, Direct, Buffer, ReadBytes)
 

Functions

NTSTATUS UDFSyncCache (IN PVCB Vcb)
 
OSSTATUS __fastcall UDFTIOVerify (IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T IOBytes, IN uint32 Flags)
 
OSSTATUS UDFTWriteVerify (IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T WrittenBytes, IN uint32 Flags)
 
OSSTATUS UDFTReadVerify (IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T ReadBytes, IN uint32 Flags)
 
OSSTATUS UDFTRead (PVOID _Vcb, PVOID Buffer, SIZE_T Length, ULONG LBA, PSIZE_T ReadBytes, ULONG Flags=0)
 
OSSTATUS UDFTWrite (IN PVOID _Vcb, IN PVOID Buffer, IN SIZE_T Length, IN ULONG LBA, OUT PSIZE_T WrittenBytes, IN ULONG Flags=0)
 
OSSTATUS UDFDoOPC (IN PVCB Vcb)
 
OSSTATUS UDFPrepareForWriteOperation (IN PVCB Vcb, IN ULONG Lba, IN ULONG BCount)
 
OSSTATUS UDFReadDiscTrackInfo (PDEVICE_OBJECT DeviceObject, PVCB Vcb)
 
OSSTATUS UDFReadAndProcessFullToc (PDEVICE_OBJECT DeviceObject, PVCB Vcb)
 
OSSTATUS UDFUseStandard (PDEVICE_OBJECT DeviceObject, PVCB Vcb)
 
OSSTATUS UDFGetBlockSize (PDEVICE_OBJECT DeviceObject, PVCB Vcb)
 
OSSTATUS UDFGetDiskInfo (IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb)
 
VOID NTAPI UDFEjectReqWaiter (IN PVOID Context)
 
VOID UDFStopEjectWaiter (PVCB Vcb)
 
OSSTATUS UDFPrepareForReadOperation (IN PVCB Vcb, IN uint32 Lba, IN uint32 BCount)
 
VOID UDFUpdateNWA (PVCB Vcb, ULONG LBA, ULONG BCount, OSSTATUS RC)
 
OSSTATUS UDFDoDismountSequence (IN PVCB Vcb, IN PPREVENT_MEDIA_REMOVAL_USER_IN Buf, IN BOOLEAN Eject)
 
OSSTATUS UDFReadInSector (IN PVCB Vcb, IN BOOLEAN Translate, IN ULONG Lba, IN ULONG i, IN ULONG l, IN BOOLEAN Direct, OUT PCHAR Buffer, OUT PSIZE_T ReadBytes)
 
OSSTATUS UDFReadData (IN PVCB Vcb, IN BOOLEAN Translate, IN LONGLONG Offset, IN ULONG Length, IN BOOLEAN Direct, OUT PCHAR Buffer, OUT PSIZE_T ReadBytes)
 
OSSTATUS UDFWriteSectors (IN PVCB Vcb, IN BOOLEAN Translate, IN ULONG Lba, IN ULONG WBCount, IN BOOLEAN Direct, IN PCHAR Buffer, OUT PSIZE_T WrittenBytes)
 
OSSTATUS UDFWriteInSector (IN PVCB Vcb, IN BOOLEAN Translate, IN ULONG Lba, IN ULONG i, IN ULONG l, IN BOOLEAN Direct, OUT PCHAR Buffer, OUT PSIZE_T WrittenBytes)
 
OSSTATUS UDFWriteData (IN PVCB Vcb, IN BOOLEAN Translate, IN LONGLONG Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN PCHAR Buffer, OUT PSIZE_T WrittenBytes)
 
OSSTATUS UDFResetDeviceDriver (IN PVCB Vcb, IN PDEVICE_OBJECT TargetDeviceObject, IN BOOLEAN Unlock)
 

Variables

BOOLEAN open_as_device
 
BOOLEAN opt_invalidate_volume
 
ULONG LockMode
 

Macro Definition Documentation

◆ PH_EX_WRITE

#define PH_EX_WRITE   0x80000000

Definition at line 69 of file phys_lib.h.

◆ PH_IO_LOCKED

#define PH_IO_LOCKED   0x20000000

Definition at line 70 of file phys_lib.h.

◆ PH_LOCK_CACHE

#define PH_LOCK_CACHE   0x10000000

Definition at line 67 of file phys_lib.h.

◆ PH_TMP_BUFFER

#define PH_TMP_BUFFER   1

Definition at line 65 of file phys_lib.h.

◆ PH_VCB_IN_RETLEN

#define PH_VCB_IN_RETLEN   2

Definition at line 66 of file phys_lib.h.

◆ UDFReadSectors

#define UDFReadSectors (   Vcb,
  Translate,
  Lba,
  BCount,
  Direct,
  Buffer,
  ReadBytes 
)
Value:
(( WCacheIsInitialized__(&((Vcb)->FastCache)) && (KeGetCurrentIrql() < DISPATCH_LEVEL)) ? \
(WCacheReadBlocks__(&((Vcb)->FastCache), Vcb, Buffer, Lba, BCount, ReadBytes, Direct)) : \
(UDFTRead(Vcb, Buffer, ((SIZE_T)(BCount))<<((Vcb)->BlockSizeBits), Lba, ReadBytes, 0)))
Definition: bufpool.h:45
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define Vcb
Definition: cdprocs.h:1415
OSSTATUS UDFTRead(PVOID _Vcb, PVOID Buffer, SIZE_T Length, ULONG LBA, PSIZE_T ReadBytes, ULONG Flags=0)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
BOOLEAN WCacheIsInitialized__(IN PW_CACHE Cache)
OSSTATUS WCacheReadBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN PCHAR Buffer, IN lba_t Lba, IN ULONG BCount, OUT PSIZE_T ReadBytes, IN BOOLEAN CachedOnly)

Definition at line 126 of file phys_lib.h.

Function Documentation

◆ UDFDoDismountSequence()

OSSTATUS UDFDoDismountSequence ( IN PVCB  Vcb,
IN PPREVENT_MEDIA_REMOVAL_USER_IN  Buf,
IN BOOLEAN  Eject 
)

Definition at line 704 of file phys_eject.cpp.

709{
710 LARGE_INTEGER delay;
711// OSSTATUS RC;
712 ULONG i;
713
714 // flush system cache
716 UDFPrint(("UDFDoDismountSequence:\n"));
717
718 delay.QuadPart = -1000000; // 0.1 sec
720 // wait for completion of all backgroung writes
721 while(Vcb->BGWriters) {
722 delay.QuadPart = -5000000; // 0.5 sec
724 }
725 // release WCache
726 WCacheRelease__(&(Vcb->FastCache));
727
728 UDFAcquireResourceExclusive(&(Vcb->IoResource), TRUE);
729
730 // unlock media, drop our own Locks
731 if(Vcb->VCBFlags & UDF_VCB_FLAGS_REMOVABLE_MEDIA) {
732 UDFPrint((" cleanup tray-lock (%d+2):\n", Vcb->MediaLockCount));
733 for(i=0; i<Vcb->MediaLockCount+2; i++) {
734 Buf->PreventMediaRemoval = FALSE;
736 Vcb->TargetDeviceObject,
738 NULL,0,
739 FALSE,NULL);
741 }
742 delay.QuadPart = -2000000; // 0.2 sec
743 }
744
745 if(!Vcb->ForgetVolume) {
746
747 if(!UDFIsDvdMedia(Vcb)) {
748 // send speed limits to drive
749 UDFPrint((" Restore drive speed on dismount\n"));
750 Vcb->SpeedBuf.ReadSpeed = Vcb->MaxReadSpeed;
751 Vcb->SpeedBuf.WriteSpeed = Vcb->MaxWriteSpeed;
753 Vcb->TargetDeviceObject,
754 &(Vcb->SpeedBuf),sizeof(SET_CD_SPEED_USER_IN),
755 NULL,0,TRUE,NULL);
756 }
757
758 if(Vcb->VCBFlags & UDF_VCB_FLAGS_OUR_DEVICE_DRIVER) {
760
761 // reset driver
762 UDFResetDeviceDriver(Vcb, Vcb->TargetDeviceObject, TRUE);
763 delay.QuadPart = -2000000; // 0.2 sec
765
766 memset(&CBuff,0,sizeof(CLOSE_TRK_SES_USER_IN));
767 // stop BG format
768 if(Vcb->MRWStatus) {
769 UDFPrint((" Stop background formatting\n"));
770
771 CBuff.Byte1.Flags = 0;//CloseTrkSes_Immed;
773 CBuff.TrackNum = 1;
774
776 Vcb->TargetDeviceObject,
777 &CBuff,sizeof(CLOSE_TRK_SES_USER_IN),
778 &CBuff,sizeof(CLOSE_TRK_SES_USER_IN),
779 FALSE, NULL );
780 /* } else
781 if(Vcb->MediaClassEx == CdMediaClass_DVDRW) {
782 UDFPrint((" Close BG-formatted track\n"));
783
784 CBuff.Byte1.Flags = 0;//CloseTrkSes_Immed;
785 CBuff.Byte2.Flags = CloseTrkSes_Trk;
786 CBuff.TrackNum = 1;
787
788 RC = UDFPhSendIOCTL(IOCTL_CDRW_CLOSE_TRK_SES,
789 Vcb->TargetDeviceObject,
790 &CBuff,sizeof(CLOSE_TRK_SES_USER_IN),
791 &CBuff,sizeof(CLOSE_TRK_SES_USER_IN),
792 FALSE, NULL );
793 */
794 }
795 // reset driver
796 UDFResetDeviceDriver(Vcb, Vcb->TargetDeviceObject, TRUE);
797 delay.QuadPart = -1000000; // 0.1 sec
799 }
800 // eject media
801 if(Eject &&
802 (Vcb->VCBFlags & UDF_VCB_FLAGS_REMOVABLE_MEDIA)) {
803
805 Vcb->TargetDeviceObject,
806 NULL,0,
807 NULL,0,
808 FALSE,NULL);
809 }
810 // notify media change
811 /* if(Vcb->VCBFlags & UDF_VCB_FLAGS_OUR_DEVICE_DRIVER) {
812 ((PNOTIFY_MEDIA_CHANGE_USER_IN)Buf)->Autorun = FALSE;
813 RC = UDFPhSendIOCTL(IOCTL_CDRW_NOTIFY_MEDIA_CHANGE,
814 Vcb->TargetDeviceObject,
815 Buf,sizeof(NOTIFY_MEDIA_CHANGE_USER_IN),
816 NULL,0,
817 FALSE,NULL);
818 }*/
819 }
820 UDFReleaseResource(&(Vcb->IoResource));
821 // unregister shutdown notification
822 if(Vcb->ShutdownRegistered) {
823 IoUnregisterShutdownNotification(Vcb->VCBDeviceObject);
824 Vcb->ShutdownRegistered = FALSE;
825 }
826 // allow media change checks (this will lead to dismount)
827 // ... and make it Read-Only... :-\~
828 Vcb->VCBFlags &= ~UDF_VCB_FLAGS_MEDIA_LOCKED;
829
830 // Return back XP CD Burner Volume
831/*
832 if (Vcb->CDBurnerVolumeValid) {
833 RtlWriteRegistryValue(RTL_REGISTRY_USER | RTL_REGISTRY_OPTIONAL,
834 REG_CD_BURNER_KEY_NAME,REG_CD_BURNER_VOLUME_NAME,
835 REG_SZ,(PVOID)&(Vcb->CDBurnerVolume),sizeof(Vcb->CDBurnerVolume));
836 ExFreePool(Vcb->CDBurnerVolume.Buffer);
837 }
838*/
839 UDFPrint((" set UnsafeIoctl\n"));
840 Vcb->VCBFlags |= UDF_VCB_FLAGS_UNSAFE_IOCTL;
841
842 return STATUS_SUCCESS;
843} // end UDFDoDismountSequence()
#define CloseTrkSes_Ses
Definition: cdrw_hw.h:556
#define IOCTL_CDRW_CLOSE_TRK_SES
Definition: cdrw_usr.h:89
#define IOCTL_CDRW_SET_SPEED
Definition: cdrw_usr.h:80
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI UDFPhSendIOCTL(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN OverrideVerify, OUT PIO_STATUS_BLOCK Iosb OPTIONAL)
Definition: env_spec.cpp:511
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
ULONG UDFFlushLogicalVolume(IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp, IN PVCB Vcb, IN ULONG FlushFlags)
Definition: flush.cpp:506
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define KernelMode
Definition: asm.h:34
#define IOCTL_STORAGE_EJECT_MEDIA
Definition: ntddstor.h:107
#define IOCTL_STORAGE_MEDIA_REMOVAL
Definition: ntddstor.h:104
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
OSSTATUS UDFResetDeviceDriver(IN PVCB Vcb, IN PDEVICE_OBJECT TargetDeviceObject, IN BOOLEAN Unlock)
Definition: phys_lib.cpp:4199
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
union _CLOSE_TRK_SES_USER_IN::@935 Byte2
union _CLOSE_TRK_SES_USER_IN::@934 Byte1
uint32_t ULONG
Definition: typedefs.h:59
#define UDF_VCB_FLAGS_REMOVABLE_MEDIA
Definition: udf_common.h:468
#define UDFIsDvdMedia(Vcb)
Definition: udf_common.h:524
#define UDF_VCB_FLAGS_UNSAFE_IOCTL
Definition: udf_common.h:488
#define UDF_VCB_FLAGS_OUR_DEVICE_DRIVER
Definition: udf_common.h:466
#define UDFPrint(Args)
Definition: udffs.h:223
LONGLONG QuadPart
Definition: typedefs.h:114
VOID WCacheRelease__(IN PW_CACHE Cache)

Referenced by UDFCommonDeviceControl(), UDFCommonShutdown(), UDFDismountVolume(), UDFEjectReqWaiter(), UDFInvalidateVolumes(), UDFPnpQueryRemove(), UDFPnpRemove(), and UDFPnpSurpriseRemove().

◆ UDFDoOPC()

OSSTATUS UDFDoOPC ( IN PVCB  Vcb)

Definition at line 850 of file phys_lib.cpp.

853{
854 OSSTATUS RC;
855 if(Vcb->OPCNum && !Vcb->OPCDone) {
856 UDFPrint(("UDFDoOPC\n"));
857 if(!Vcb->OPCh) {
858 Vcb->OPCh =
861 }
862 if(!Vcb->OPCh)
864 Vcb->OPCh->DoOpc = TRUE;
865 Vcb->OPCh->OpcBlocksNumber = 0;
866 RC = UDFPhSendIOCTL(IOCTL_CDRW_SEND_OPC_INFO, Vcb->TargetDeviceObject,
867 (void*)(Vcb->OPCh),sizeof(SEND_OPC_INFO_HEADER_USER_IN),
868 NULL,0,
869 FALSE, NULL);
870 if(!OS_SUCCESS(RC)) {
871 UDFPrint(("UDFDoOPC failed\n"));
872 Vcb->OPCNum = 0;
873// Vcb->VCBFlags |= UDF_VCB_FLAGS_OPC_FAILED;
874 }
875 Vcb->OPCDone = TRUE;
876 }
877 return RC;
878} // end UDFDoOPC()
struct _SEND_OPC_INFO_HEADER_USER_IN * PSEND_OPC_INFO_HEADER_USER_IN
#define IOCTL_CDRW_SEND_OPC_INFO
Definition: cdrw_usr.h:109
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
#define OSSTATUS
Definition: env_spec_w32.h:57
#define NonPagedPool
Definition: env_spec_w32.h:307
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by UDFPrepareForWriteOperation().

◆ UDFEjectReqWaiter()

VOID NTAPI UDFEjectReqWaiter ( IN PVOID  Context)

Referenced by UDFStartEjectWaiter().

◆ UDFGetBlockSize()

OSSTATUS UDFGetBlockSize ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb 
)

◆ UDFGetDiskInfo()

OSSTATUS UDFGetDiskInfo ( IN PDEVICE_OBJECT  DeviceObject,
IN PVCB  Vcb 
)

Definition at line 3050 of file phys_lib.cpp.

3054{
3056 int8* ioBuf = (int8*)MyAllocatePool__(NonPagedPool,4096);
3057 uint8 MediaType;
3058 PLUN_WRITE_PERF_DESC_USER WPerfDesc;
3059 uint32 i;
3060// BOOLEAN MRW_problem = FALSE;
3061 uint32 SavedFeatures = 0;
3062#ifdef UDF_FORMAT_MEDIA
3063 PUDFFmtState fms = Vcb->fms;
3064#else
3065 #define fms FALSE
3066#endif //UDF_FORMAT_MEDIA
3067
3068 UDFPrint(("UDFGetDiskInfo\n"));
3069
3070 if(!ioBuf) {
3072 }
3073
3074 _SEH2_TRY {
3076 if(!OS_SUCCESS(RC)) try_return(RC);
3077
3078
3079 // Get lower driver signature
3081 ioBuf,sizeof(GET_SIGNATURE_USER_OUT),
3082 ioBuf,sizeof(GET_SIGNATURE_USER_OUT),
3083 TRUE,NULL);
3084
3085 if(!OS_SUCCESS(RC)) {
3086
3088#ifdef _BROWSE_UDF_
3089 if(!NT_SUCCESS(RC) || fms)
3090 try_return(RC);
3091
3092 // assume Device Recordable for now
3093 goto GetSignatureFailed;
3094#endif //_BROWSE_UDF_
3095 }
3096
3097 UDFPrint(("UDF: Signature of low driver is : %s \n",
3098 ((PGET_SIGNATURE_USER_OUT)(ioBuf))->VendorId));
3099
3100 if(!strncmp( (const char *)(&( ((PGET_SIGNATURE_USER_OUT)(ioBuf))->VendorId[0]) ),
3102 UDFPrint(("UDF: *****************************************\n"));
3103 UDFPrint(("UDF: ********* Our Device Driver Found ******\n"));
3104 UDFPrint(("UDF: *****************************************\n"));
3105
3106 (Vcb->VCBFlags) |= UDF_VCB_FLAGS_OUR_DEVICE_DRIVER;
3107#ifndef _BROWSE_UDF_
3108 // reset driver
3109#ifdef UDF_FORMAT_MEDIA
3110 if(!fms->opt_probe) {
3111#endif //UDF_FORMAT_MEDIA
3112 UDFResetDeviceDriver(Vcb, Vcb->TargetDeviceObject, FALSE);
3113 // lock it
3114 ((PPREVENT_MEDIA_REMOVAL_USER_IN)(ioBuf))->PreventMediaRemoval = TRUE;
3117 ioBuf,sizeof(PREVENT_MEDIA_REMOVAL_USER_IN),
3118 NULL,0,
3119 FALSE, NULL);
3120#ifdef UDF_FORMAT_MEDIA
3121 }
3122#endif //UDF_FORMAT_MEDIA
3123#endif //_BROWSE_UDF_
3124//#else //_BROWSE_UDF_
3125 // get device features
3128 NULL,0,
3129 ioBuf,sizeof(GET_DEVICE_INFO_USER_OUT),
3130 FALSE,NULL);
3131
3132 Vcb->SavedFeatures =
3133 SavedFeatures = ((PGET_DEVICE_INFO_USER_OUT)ioBuf)->Features;
3134 if(!(SavedFeatures & CDRW_FEATURE_SYNC_ON_WRITE)) {
3135 UDFPrint(("UDFGetDiskInfo: UDF_VCB_IC_NO_SYNCCACHE_AFTER_WRITE\n"));
3137 }
3138 if(!(SavedFeatures & CDRW_FEATURE_FORCE_SYNC_BEFORE_READ)) {
3139 UDFPrint(("UDFGetDiskInfo: UDF_VCB_IC_SYNCCACHE_BEFORE_READ\n"));
3140 Vcb->CompatFlags |= UDF_VCB_IC_SYNCCACHE_BEFORE_READ;
3141 }
3142 if(SavedFeatures & CDRW_FEATURE_BAD_RW_SEEK) {
3143 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_BAD_RW_SEEK\n"));
3144 Vcb->CompatFlags |= UDF_VCB_IC_BAD_RW_SEEK;
3145 }
3146 // we must check if this is FP-formatted disk in old devices
3147 // independently of MediaType they report
3148 if(SavedFeatures & CDRW_FEATURE_FP_ADDRESSING_PROBLEM) {
3149 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_FP_ADDRESSING_PROBLEM ?\n"));
3150 Vcb->CompatFlags |= UDF_VCB_IC_FP_ADDR_PROBLEM;
3151 }
3152 if(SavedFeatures & CDRW_FEATURE_MRW_ADDRESSING_PROBLEM) {
3153 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_MRW_ADDRESSING_PROBLEM ?\n"));
3154 }
3155 if(SavedFeatures & CDRW_FEATURE_FORCE_SYNC_ON_WRITE) {
3156 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_FORCE_SYNC_ON_WRITE\n"));
3158 }
3159 if(SavedFeatures & CDRW_FEATURE_BAD_DVD_LAST_LBA) {
3160 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_BAD_DVD_LAST_LBA\n"));
3161 Vcb->CompatFlags |= UDF_VCB_IC_BAD_DVD_LAST_LBA;
3162 }
3163 if(SavedFeatures & CDRW_FEATURE_STREAMING) {
3164 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_STREAMING\n"));
3165 }
3166 if(SavedFeatures & CDRW_FEATURE_OPC) {
3167 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_OPC -> assume OPCNum=1\n"));
3168 Vcb->OPCNum = 1;
3169 }
3170#ifdef UDF_FORMAT_MEDIA
3171 if(SavedFeatures & CDRW_FEATURE_FULL_BLANK_ON_FORMAT) {
3172 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_FULL_BLANK_ON_FORMAT\n"));
3173 if((fms->opt_probe || fms->opt_smart_f)/* &&
3174 (fms->format_media && fms->blank_media*/) {
3175 UDFPrint(("UDFGetDiskInfo: force Full Erase\n"));
3176 fms->opt_qblank = FALSE;
3177 }
3178 }
3179#endif //UDF_FORMAT_MEDIA
3180#ifdef _BROWSE_UDF_
3181 // get device buffer size
3184 NULL,0,
3185 ioBuf,sizeof(BUFFER_CAPACITY_BLOCK_USER_OUT),
3186 FALSE,NULL);
3187 if(NT_SUCCESS(RC)) {
3188 Vcb->CdrwBufferSize = ((PBUFFER_CAPACITY_BLOCK_USER_OUT)ioBuf)->BufferLength;
3189 } else {
3190 Vcb->CdrwBufferSize = 0;
3191 }
3192 UDFPrint(("UDFGetDiskInfo: CdrwBufferSize = %dKb\n", Vcb->CdrwBufferSize / 1024));
3193 Vcb->CdrwBufferSizeCounter = 0;
3194#endif //_BROWSE_UDF_
3195 // get media type
3197 NULL,0,ioBuf,sizeof(GET_MEDIA_TYPE_USER_OUT),
3198 FALSE, NULL);
3199 if(!OS_SUCCESS(RC)) goto Try_FullToc;
3200 Vcb->MediaType =
3201 MediaType = ((PGET_MEDIA_TYPE_USER_OUT)ioBuf)->MediaType;
3202 UDFPrint(("UDFGetDiskInfo: MediaType %x\n", MediaType));
3203
3204#ifndef UDF_FORMAT_MEDIA
3205 // we shall ignore audio-disks
3206 switch(MediaType) {
3213// case :
3214 UDFPrint(("UDFGetDiskInfo: we shall ignore audio-disks...\n"));
3216 }
3217#endif //UDF_FORMAT_MEDIA
3218
3219 UDFPrint(("UDFGetDiskInfo: Check DVD-disks...\n"));
3221 NULL,0,ioBuf,sizeof(GET_MEDIA_TYPE_EX_USER_OUT),
3222 FALSE, NULL);
3223 if(!OS_SUCCESS(RC)) goto Try_FullToc;
3224 Vcb->MediaClassEx =
3225 MediaType = (((PGET_MEDIA_TYPE_EX_USER_OUT)ioBuf)->MediaClass);
3226 UDFPrint(("UDFGetDiskInfo: MediaClassEx %x\n", MediaType));
3227
3228#ifdef _BROWSE_UDF_
3229 if(!fms) {
3230
3231 switch(MediaType) {
3232
3233 case CdMediaClass_CDR:
3234 case CdMediaClass_DVDR:
3235 case CdMediaClass_DVDpR:
3237 case CdMediaClass_BDR:
3238 UDFPrint(("UDFGetDiskInfo: MediaClass R\n"));
3239 Vcb->MediaType = MediaType_UnknownSize_CDR;
3240 break;
3241 case CdMediaClass_CDRW:
3242
3243 if(SavedFeatures & CDRW_FEATURE_MRW_ADDRESSING_PROBLEM) {
3244 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_MRW_ADDRESSING_PROBLEM on CD-RW\n"));
3245 Vcb->CompatFlags |= UDF_VCB_IC_MRW_ADDR_PROBLEM;
3246 }
3247
3248 case CdMediaClass_DVDRW:
3253 case CdMediaClass_BDRE:
3254 UDFPrint(("UDFGetDiskInfo: MediaClass RW\n"));
3255 Vcb->MediaType = MediaType_UnknownSize_CDRW;
3256 break;
3257 case CdMediaClass_CDROM:
3260 case CdMediaClass_BDROM:
3261 UDFPrint(("UDFGetDiskInfo: MediaClass ROM\n"));
3262 Vcb->MediaType = MediaType_Unknown;
3263 // Vcb->MediaType = MediaType_UnknownSize_CDROM;
3264 break;
3265 default:
3266 UDFPrint(("UDFGetDiskInfo: MediaClass Unknown\n"));
3267 Vcb->MediaType = MediaType_Unknown;
3268 break;
3269 }
3270 MediaType = Vcb->MediaType;
3271
3272 }
3273#endif //_BROWSE_UDF_
3274
3275#ifdef UDF_FORMAT_MEDIA
3276
3277 if(fms) {
3278
3279 switch(MediaType) {
3280 case CdMediaClass_CDR:
3281 UDFPrint(("CdMediaClass_CDR\n"));
3282 MediaType = MediaType_UnknownSize_CDR;
3283 if(fms->opt_media == MT_AUTO)
3284 fms->opt_media = MT_CDR;
3285 break;
3286 case CdMediaClass_DVDR:
3287 UDFPrint(("CdMediaClass_DVDR -> MediaType_UnknownSize_CDR\n"));
3288 MediaType = MediaType_UnknownSize_CDR;
3289 if(fms->opt_media == MT_AUTO)
3290 fms->opt_media = MT_DVDR;
3291 break;
3292 case CdMediaClass_DVDpR:
3293 UDFPrint(("CdMediaClass_DVDpR -> MediaType_UnknownSize_CDR\n"));
3294 MediaType = MediaType_UnknownSize_CDR;
3295 if(fms->opt_media == MT_AUTO)
3296 fms->opt_media = MT_DVDpR;
3297 break;
3299 UDFPrint(("CdMediaClass_HD_DVDR -> MediaType_UnknownSize_CDR\n"));
3300 MediaType = MediaType_UnknownSize_CDR;
3301 if(fms->opt_media == MT_AUTO)
3302 fms->opt_media = MT_DVDR;
3303 break;
3304 case CdMediaClass_BDR:
3305 UDFPrint(("CdMediaClass_BDR -> MediaType_UnknownSize_CDR\n"));
3306 MediaType = MediaType_UnknownSize_CDR;
3307 if(fms->opt_media == MT_AUTO)
3308 fms->opt_media = MT_DVDR;
3309 break;
3310 case CdMediaClass_CDRW:
3311 UDFPrint(("CdMediaClass_CDRW\n"));
3312 MediaType = MediaType_UnknownSize_CDRW;
3313 if(fms->opt_media == MT_AUTO)
3314 fms->opt_media = MT_CDRW;
3315 if(SavedFeatures & CDRW_FEATURE_MRW_ADDRESSING_PROBLEM) {
3316 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_MRW_ADDRESSING_PROBLEM on CD-RW\n"));
3317 Vcb->CompatFlags |= UDF_VCB_IC_MRW_ADDR_PROBLEM;
3318 }
3319 break;
3320 case CdMediaClass_DVDRW:
3321 UDFPrint((" CdMediaClass_DVDRW -> MediaType_UnknownSize_CDRW\n"));
3322 if(fms->opt_media == MT_AUTO)
3323 fms->opt_media = MT_DVDRW;
3324 MediaType = MediaType_UnknownSize_CDRW;
3325 break;
3327 UDFPrint((" CdMediaClass_DVDpRW -> MediaType_UnknownSize_CDRW\n"));
3328 if(fms->opt_media == MT_AUTO)
3329 fms->opt_media = MT_DVDpRW;
3330 MediaType = MediaType_UnknownSize_CDRW;
3331 break;
3333 UDFPrint((" CdMediaClass_DVDRAM -> MediaType_UnknownSize_CDRW\n"));
3334 if(fms->opt_media == MT_AUTO)
3335 fms->opt_media = MT_DVDRAM;
3336 MediaType = MediaType_UnknownSize_CDRW;
3337 break;
3339 UDFPrint((" CdMediaClass_HD_DVDRW -> MediaType_UnknownSize_CDRW\n"));
3340 if(fms->opt_media == MT_AUTO)
3341 fms->opt_media = MT_DVDRW;
3342 MediaType = MediaType_UnknownSize_CDRW;
3343 break;
3345 UDFPrint((" CdMediaClass_HD_DVDRAM -> MediaType_UnknownSize_CDRW\n"));
3346 if(fms->opt_media == MT_AUTO)
3347 fms->opt_media = MT_DVDRAM;
3348 MediaType = MediaType_UnknownSize_CDRW;
3349 break;
3350 case CdMediaClass_BDRE:
3351 UDFPrint((" CdMediaClass_BDRE -> MediaType_UnknownSize_CDRW\n"));
3352 if(fms->opt_media == MT_AUTO)
3353 fms->opt_media = MT_DVDRW;
3354 MediaType = MediaType_UnknownSize_CDRW;
3355 break;
3357 UDFPrint((" CdMediaClass_NoDiscPresent -> MediaType_NoDiscPresent\n"));
3358 MediaType = MediaType_NoDiscPresent;
3359 fms->opt_media = MT_none;
3360 break;
3362 UDFPrint((" CdMediaClass_DoorOpen -> MediaType_DoorOpen\n"));
3363 MediaType = MediaType_DoorOpen;
3364 fms->opt_media = MT_none;
3365 break;
3366 default:
3367 UDFPrint((" MediaType_Unknown\n"));
3368 MediaType = MediaType_Unknown;
3369 break;
3370 }
3371 if(!apply_force_r(fms)) {
3373 }
3374 }
3375
3376#endif //UDF_FORMAT_MEDIA
3377
3378 Vcb->DVD_Mode = (((PGET_MEDIA_TYPE_EX_USER_OUT)ioBuf)->MediaClassEx == CdMediaClassEx_DVD);
3379 Vcb->PhMediaCapFlags = ((PGET_MEDIA_TYPE_EX_USER_OUT)ioBuf)->CapFlags;
3380 Vcb->WriteParamsReq = (Vcb->PhMediaCapFlags & CdCapFlags_WriteParamsReq) ? TRUE : FALSE;
3381 if(Vcb->DVD_Mode &&
3382 !(Vcb->PhMediaCapFlags & CdCapFlags_RandomWritable)) {
3383 UDFPrint(("UDFGetDiskInfo: DVD && !CdCapFlags_RandomWritable\n"));
3384 UDFPrint((" Read-only volume\n"));
3385// BrutePoint();
3386#ifndef UDF_CDRW_EMULATION_ON_ROM
3388#endif
3389 }
3390#ifdef UDF_FORMAT_MEDIA
3391 if(fms) {
3392 if((MediaType == MediaType_NoDiscPresent) ||
3393 (MediaType == MediaType_DoorOpen)) {
3394 UserPrint(("No media in device\n"));
3396 }
3397 }
3398#endif //UDF_FORMAT_MEDIA
3399 if(!Vcb->WriteParamsReq) {
3400 UDFPrint(("UDFGetDiskInfo: do not use WriteParams\n"));
3401 }
3402 if(Vcb->PhMediaCapFlags & CdCapFlags_Cav) {
3403 UDFPrint(("UDFGetDiskInfo: Use CAV (1)\n"));
3404 Vcb->VCBFlags |= UDF_VCB_FLAGS_USE_CAV;
3405 }
3406
3407#ifdef _BROWSE_UDF_
3408 if(!fms) {
3409 // check if this device is capable to write on such media
3410 if(UDFIsDvdMedia(Vcb)) {
3411 //RC =
3412 UDFPrint(("UDFGetDiskInfo: update defaulted LastLBA\n"));
3414 //if(!OS_SUCCESS(RC)) goto Try_FullToc;
3415 } else {
3416 if((SavedFeatures & CDRW_FEATURE_MRW_ADDRESSING_PROBLEM) &&
3417 (SavedFeatures & UDF_VCB_IC_FP_ADDR_PROBLEM)) {
3418 UDFPrint(("UDFGetDiskInfo: CDRW_FEATURE_MRW_ADDRESSING_PROBLEM on old CD-ROM\n"));
3419 Vcb->CompatFlags |= UDF_VCB_IC_MRW_ADDR_PROBLEM;
3420 }
3421 }
3422 }
3423#endif //_BROWSE_UDF_
3424
3425/*#ifdef UDF_FORMAT_MEDIA
3426 if(fms) {
3427 if(MediaType == CdMediaClass_DVDRW) {
3428 UserPrint(("Not empty media. Erase required.\n"));
3429 my_exit(fms, MKUDF_BLANK_FORMAT_REQUIRED);
3430 }
3431 }
3432#endif //UDF_FORMAT_MEDIA*/
3433
3434#define cap ((PGET_CAPABILITIES_3_USER_OUT)ioBuf)
3435 // get device capabilities
3437 NULL,0,ioBuf,sizeof(GET_CAPABILITIES_3_USER_OUT),
3438 FALSE, NULL);
3439 if(!OS_SUCCESS(RC)) goto Try_FullToc;
3440
3441 // check if this device is capable to write on such media
3443 NULL,0,NULL,0,FALSE, NULL);
3444 if(RC != STATUS_SUCCESS) {
3445 UDFPrint(("IS_WRITABLE - false, doing additional check...\n"));
3446 if( ((MediaType >= MediaType_UnknownSize_CDRW) && !(cap->WriteCap & DevCap_write_cd_rw)) ||
3447 ((MediaType >= MediaType_UnknownSize_CDR) && !(cap->WriteCap & DevCap_write_cd_r)) ||
3448 (MediaType < MediaType_UnknownSize_CDR) ) {
3449 UserPrint(("Hardware Read-only volume\n"));
3450#ifndef UDF_CDRW_EMULATION_ON_ROM
3452#endif //UDF_CDRW_EMULATION_ON_ROM
3453#ifdef UDF_FORMAT_MEDIA
3454 if(fms && !fms->opt_read_iso)
3455 my_exit(fms, MKUDF_HW_READ_ONLY);
3456#endif //UDF_FORMAT_MEDIA
3457 }
3458 } else {
3459 UDFPrint(("Writable disk\n"));
3460 }
3461 Vcb->MaxWriteSpeed = cap->MaximumWriteSpeedSupported;
3462 Vcb->MaxReadSpeed = cap->MaximumSpeedSupported;
3463 if(cap->PageLength >= (sizeof(GET_CAPABILITIES_3_USER_OUT)-2)) {
3464 Vcb->CurSpeed = max(cap->CurrentSpeed, cap->CurrentWriteSpeed3);
3465 if(cap->LunWPerfDescriptorCount && cap->LunWPerfDescriptorCount != 0xffff) {
3466 ULONG n;
3467 UDFPrint(("Write performance descriptor(s) found: %x\n", cap->LunWPerfDescriptorCount));
3468 n = (4096 - sizeof(GET_CAPABILITIES_3_USER_OUT)) / sizeof(LUN_WRITE_PERF_DESC_USER);
3469 n = min(n, cap->LunWPerfDescriptorCount);
3470 // get device capabilities
3474 TRUE,NULL);
3475 if(OS_SUCCESS(RC)) {
3476 WPerfDesc = (PLUN_WRITE_PERF_DESC_USER)(ioBuf + sizeof(GET_CAPABILITIES_3_USER_OUT));
3477 n = FALSE;
3478 for(i = 0; i<n; i++) {
3479 if((WPerfDesc[i].RotationControl & LunWPerf_RotCtrl_Mask) == LunWPerf_RotCtrl_CAV) {
3480 Vcb->VCBFlags |= UDF_VCB_FLAGS_USE_CAV;
3481 if(!n) {
3482 Vcb->CurSpeed = WPerfDesc[i].WriteSpeedSupported;
3483 n = TRUE;
3484 UDFPrint(("Use CAV\n"));
3485 } else {
3486 Vcb->CurSpeed = max(WPerfDesc[i].WriteSpeedSupported, Vcb->CurSpeed);
3487 }
3488 UDFPrint(("supports speed %dX\n", Vcb->CurSpeed/176));
3489 //break;
3490 }
3491 }
3492 if(n) {
3493 UDFPrint(("Set r/w speeds to %dX\n", Vcb->CurSpeed/176));
3494 Vcb->MaxWriteSpeed =
3495 Vcb->MaxReadSpeed = Vcb->CurSpeed;
3496 }
3497 }
3498 }
3499 } else {
3500 Vcb->CurSpeed = max(cap->CurrentSpeed, cap->CurrentWriteSpeed);
3501 }
3502 UDFPrint((" Speeds r/w %dX/%dX\n", Vcb->CurSpeed/176, cap->CurrentWriteSpeed/176));
3503
3504 if(Vcb->VCBFlags & UDF_VCB_FLAGS_USE_CAV) {
3505 // limit both read & write speed to last write speed for CAV mode
3506 // some drives damage data when speed is adjusted during recording process
3507 // even in packet mode
3509 }
3511
3512#undef cap
3513#ifdef UDF_FORMAT_MEDIA
3514 if(fms) {
3515 if( (fms->auto_media || (fms->opt_media == MT_AUTO)) &&
3516 (fms->opt_media < MT_DVDR) ) {
3517 if(MediaType < MediaType_UnknownSize_CDRW) {
3518 fms->opt_media = MT_CDR;
3519 } else {
3520 fms->opt_media = MT_CDRW;
3521 }
3522 }
3523 if(!apply_force_r(fms)) {
3525 }
3526 }
3527#endif //UDF_FORMAT_MEDIA
3529
3530 if(!OS_SUCCESS(RC)) {
3531 // may be we have a CD-ROM device
3532Try_FullToc:
3533 UDFPrint(("Hardware Read-only volume (2)\n"));
3534// BrutePoint();
3535#ifndef UDF_CDRW_EMULATION_ON_ROM
3537#endif
3538
3540
3541 if(!OS_SUCCESS(RC)) {
3543 if(!OS_SUCCESS(RC)) try_return(RC);
3544 }
3545
3546 }
3547 } else {
3548#ifdef _BROWSE_UDF_
3549GetSignatureFailed:
3550#endif
3552 if(!OS_SUCCESS(RC)) try_return(RC);
3553 }
3554
3555try_exit: NOTHING;
3556
3557 } _SEH2_FINALLY {
3558
3559 if(ioBuf) MyFreePool__(ioBuf);
3560
3561 if(UDFIsDvdMedia(Vcb) &&
3562 (Vcb->CompatFlags & UDF_VCB_IC_BAD_DVD_LAST_LBA) &&
3563 (Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY) &&
3564 Vcb->LastLBA &&
3565 (Vcb->LastLBA < DEFAULT_LAST_LBA_DVD)) {
3566 UDFPrint(("UDF: Bad DVD last LBA %x, fixup!\n", Vcb->LastLBA));
3567 Vcb->LastLBA = DEFAULT_LAST_LBA_DVD;
3568 Vcb->NWA = 0;
3569 }
3570
3571
3572 if(UDFIsDvdMedia(Vcb) && !Vcb->FirstLBA && !Vcb->LastPossibleLBA) {
3573 UDFPrint(("UDF: Empty DVD. Use bogus values for now\n"));
3574 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_DVD;
3575 Vcb->LastLBA = 0;
3576 }
3577
3578 if((Vcb->LastPossibleLBA & 0x80000000) || (Vcb->LastPossibleLBA < Vcb->LastLBA)) {
3579 UDFPrint(("UDF: bad LastPossibleLBA %x -> %x\n", Vcb->LastPossibleLBA, Vcb->LastLBA));
3580 Vcb->LastPossibleLBA = Vcb->LastLBA;
3581 }
3582 if(!Vcb->WriteBlockSize)
3583 Vcb->WriteBlockSize = PACKETSIZE_UDF*Vcb->BlockSize;
3584
3585#ifdef _BROWSE_UDF_
3586 if(Vcb->TrackMap) {
3587 if(Vcb->TrackMap[Vcb->LastTrackNum].LastLba > Vcb->NWA) {
3588 if(Vcb->NWA) {
3589 if(Vcb->TrackMap[Vcb->LastTrackNum].DataParam & TrkInfo_FP) {
3590 Vcb->LastLBA = Vcb->NWA-1;
3591 } else {
3592 Vcb->LastLBA = Vcb->NWA-7-1;
3593 }
3594 }
3595 } else {
3596 if((Vcb->LastTrackNum > 1) &&
3597 (Vcb->TrackMap[Vcb->LastTrackNum-1].FirstLba >= Vcb->TrackMap[Vcb->LastTrackNum-1].LastLba)) {
3598 Vcb->LastLBA = Vcb->TrackMap[Vcb->LastTrackNum-1].LastLba;
3599 }
3600 }
3601 }
3602
3603 for(i=0; i<32; i++) {
3604 if(!(Vcb->LastPossibleLBA >> i))
3605 break;
3606 }
3607 if(i > 20) {
3608 Vcb->WCacheBlocksPerFrameSh = max(Vcb->WCacheBlocksPerFrameSh, (2*i)/5+2);
3609 Vcb->WCacheBlocksPerFrameSh = min(Vcb->WCacheBlocksPerFrameSh, 16);
3610 }
3611
3612 if(Vcb->CompatFlags & UDF_VCB_IC_FP_ADDR_PROBLEM) {
3613 // Check first 0x200 blocks
3614 UDFCheckTrackFPAddressing(Vcb, Vcb->FirstTrackNum);
3615 // if we really have such a problem, fix LastLBA
3616 if(Vcb->CompatFlags & UDF_VCB_IC_FP_ADDR_PROBLEM) {
3617 UDFPrint(("UDF: Fix LastLBA: %x -> %x\n", Vcb->LastLBA, (Vcb->LastLBA*32) / 39));
3618 Vcb->LastLBA = (Vcb->LastLBA*32) / 39;
3619 }
3620 }
3621#endif //_BROWSE_UDF_
3622
3623 if(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY) {
3624 if(!Vcb->BlankCD && Vcb->MediaType != MediaType_UnknownSize_CDRW) {
3625 UDFPrint(("UDFGetDiskInfo: R/O+!Blank+!RW -> !RAW\n"));
3626 Vcb->VCBFlags &= ~UDF_VCB_FLAGS_RAW_DISK;
3627 } else {
3628 UDFPrint(("UDFGetDiskInfo: Blank or RW\n"));
3629 }
3630 }
3631
3632 UDFPrint(("UDF: ------------------------------------------\n"));
3633 UDFPrint(("UDF: Media characteristics\n"));
3634 UDFPrint(("UDF: Last session: %d\n",Vcb->LastSession));
3635 UDFPrint(("UDF: First track in first session: %d\n",Vcb->FirstTrackNum));
3636 UDFPrint(("UDF: First track in last session: %d\n",Vcb->FirstTrackNumLastSes));
3637 UDFPrint(("UDF: Last track in last session: %d\n",Vcb->LastTrackNum));
3638 UDFPrint(("UDF: First LBA in first session: %x\n",Vcb->FirstLBA));
3639 UDFPrint(("UDF: First LBA in last session: %x\n",Vcb->FirstLBALastSes));
3640 UDFPrint(("UDF: Last LBA in last session: %x\n",Vcb->LastLBA));
3641 UDFPrint(("UDF: First writable LBA (NWA) in last session: %x\n",Vcb->NWA));
3642 UDFPrint(("UDF: Last available LBA beyond end of last session: %x\n",Vcb->LastPossibleLBA));
3643 UDFPrint(("UDF: blocks per frame: %x\n",1 << Vcb->WCacheBlocksPerFrameSh));
3644 UDFPrint(("UDF: Flags: %s%s\n",
3645 Vcb->VCBFlags & UDF_VCB_FLAGS_RAW_DISK ? "RAW " : "",
3646 Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY ? "R/O " : "WR "
3647 ));
3648 UDFPrint(("UDF: ------------------------------------------\n"));
3649
3650#ifdef UDF_FORMAT_MEDIA
3651 if(fms && fms->opt_disk_info) {
3652 UserPrint(("------------------------------------------\n"));
3653 UserPrint(("Media characteristics:\n"));
3654 UserPrint((" First writable LBA (NWA) in last session: %x\n",Vcb->NWA));
3655 UserPrint((" Last available LBA beyond end of last session: %x\n",Vcb->LastPossibleLBA));
3656 UserPrint(("------------------------------------------\n"));
3657 }
3658#endif //UDF_FORMAT_MEDIA
3659
3660 } _SEH2_END;
3661
3662 UDFPrint(("UDFGetDiskInfo: %x\n", RC));
3663 return(RC);
3664
3665} // end UDFGetDiskInfo()
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned int uint32
Definition: types.h:32
unsigned char uint8
Definition: types.h:28
#define try_return(S)
Definition: cdprocs.h:2179
#define DevCap_write_cd_rw
Definition: cdrw_hw.h:3014
#define TrkInfo_FP
Definition: cdrw_hw.h:2417
#define MediaType_Unknown
Definition: cdrw_hw.h:2465
#define MediaType_DoorOpen
Definition: cdrw_hw.h:2500
#define MediaType_UnknownSize_CDR
Definition: cdrw_hw.h:2475
#define MediaType_UnknownSize_CDRW
Definition: cdrw_hw.h:2485
#define MediaType_120mm_CDRW_AudioOnly
Definition: cdrw_hw.h:2487
#define MediaType_120mm_CDROM_AudioOnly
Definition: cdrw_hw.h:2467
#define DevCap_write_cd_r
Definition: cdrw_hw.h:3013
#define MediaType_80mm_CDRW_AudioOnly
Definition: cdrw_hw.h:2491
#define LunWPerf_RotCtrl_CAV
Definition: cdrw_hw.h:3142
#define MediaType_NoDiscPresent
Definition: cdrw_hw.h:2499
#define MediaType_80mm_CDROM_AudioOnly
Definition: cdrw_hw.h:2471
#define MediaType_120mm_CDR_AudioOnly
Definition: cdrw_hw.h:2477
#define LunWPerf_RotCtrl_Mask
Definition: cdrw_hw.h:3140
#define MediaType_80mm_CDR_AudioOnly
Definition: cdrw_hw.h:2481
#define CdMediaClass_CDR
Definition: cdrw_usr.h:744
#define IOCTL_CDRW_BUFFER_CAPACITY
Definition: cdrw_usr.h:94
#define CdMediaClass_DVDR
Definition: cdrw_usr.h:748
#define IOCTL_CDRW_GET_MEDIA_TYPE
Definition: cdrw_usr.h:84
#define CdMediaClass_DoorOpen
Definition: cdrw_usr.h:763
#define CDRW_FEATURE_BAD_RW_SEEK
Definition: cdrw_usr.h:1485
#define CdMediaClass_DVDRW
Definition: cdrw_usr.h:749
struct _GET_MEDIA_TYPE_USER_OUT * PGET_MEDIA_TYPE_USER_OUT
struct _PREVENT_MEDIA_REMOVAL_USER_IN * PPREVENT_MEDIA_REMOVAL_USER_IN
#define CdMediaClass_CDROM
Definition: cdrw_usr.h:743
struct _GET_CAPABILITIES_3_USER_OUT GET_CAPABILITIES_3_USER_OUT
#define PACKETSIZE_UDF
Definition: cdrw_usr.h:1753
#define CdMediaClass_HD_DVDRW
Definition: cdrw_usr.h:761
#define CDRW_FEATURE_BAD_DVD_LAST_LBA
Definition: cdrw_usr.h:1492
#define CDRW_FEATURE_MRW_ADDRESSING_PROBLEM
Definition: cdrw_usr.h:1490
#define CdMediaClass_CDRW
Definition: cdrw_usr.h:745
#define CDRW_FEATURE_FORCE_SYNC_ON_WRITE
Definition: cdrw_usr.h:1491
#define CDRW_FEATURE_FULL_BLANK_ON_FORMAT
Definition: cdrw_usr.h:1493
#define CDRW_FEATURE_FORCE_SYNC_BEFORE_READ
Definition: cdrw_usr.h:1495
#define CdMediaClass_BDRE
Definition: cdrw_usr.h:756
struct _LUN_WRITE_PERF_DESC_USER * PLUN_WRITE_PERF_DESC_USER
#define CdMediaClass_BDROM
Definition: cdrw_usr.h:755
#define CdCapFlags_RandomWritable
Definition: cdrw_usr.h:796
struct _GET_DEVICE_INFO_USER_OUT * PGET_DEVICE_INFO_USER_OUT
#define CdMediaClass_HD_DVDROM
Definition: cdrw_usr.h:758
struct _LUN_WRITE_PERF_DESC_USER LUN_WRITE_PERF_DESC_USER
#define CDRW_FEATURE_STREAMING
Definition: cdrw_usr.h:1494
#define CDRW_FEATURE_FP_ADDRESSING_PROBLEM
Definition: cdrw_usr.h:1489
#define CdMediaClass_HD_DVDRAM
Definition: cdrw_usr.h:759
#define IOCTL_CDRW_GET_SIGNATURE
Definition: cdrw_usr.h:95
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
#define IOCTL_CDRW_GET_DEVICE_INFO
Definition: cdrw_usr.h:119
#define CdMediaClass_DVDRAM
Definition: cdrw_usr.h:747
#define CdMediaClass_HD_DVDR
Definition: cdrw_usr.h:760
#define CdMediaClass_NoDiscPresent
Definition: cdrw_usr.h:762
#define CdMediaClass_DVDROM
Definition: cdrw_usr.h:746
struct _GET_MEDIA_TYPE_EX_USER_OUT * PGET_MEDIA_TYPE_EX_USER_OUT
#define CdMediaClass_DVDpR
Definition: cdrw_usr.h:750
#define CdCapFlags_WriteParamsReq
Definition: cdrw_usr.h:795
#define CDRW_FEATURE_OPC
Definition: cdrw_usr.h:1480
struct _BUFFER_CAPACITY_BLOCK_USER_OUT * PBUFFER_CAPACITY_BLOCK_USER_OUT
#define CDRW_FEATURE_SYNC_ON_WRITE
Definition: cdrw_usr.h:1484
#define CdCapFlags_Cav
Definition: cdrw_usr.h:797
#define IOCTL_CDRW_GET_MEDIA_TYPE_EX
Definition: cdrw_usr.h:123
#define CdMediaClass_DVDpRW
Definition: cdrw_usr.h:751
#define CdMediaClassEx_DVD
Definition: cdrw_usr.h:780
#define CdMediaClass_BDR
Definition: cdrw_usr.h:757
#define DEFAULT_LAST_LBA_DVD
Definition: cdrw_usr.h:1821
#define IOCTL_CDRW_GET_CAPABILITIES
Definition: cdrw_usr.h:82
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
char int8
Definition: platform.h:10
#define UserPrint(x)
Definition: env_spec_w32.h:202
void my_exit(int rc)
GLdouble n
Definition: glext.h:7729
GLenum cap
Definition: glext.h:9639
#define NOTHING
Definition: input_list.c:10
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define min(a, b)
Definition: monoChain.cc:55
NTSTATUS UDFSetCaching(IN PVCB Vcb)
Definition: phys_lib.cpp:4263
static const char Signature[16]
Definition: phys_lib.cpp:18
OSSTATUS UDFSetSpeeds(IN PVCB Vcb)
Definition: phys_lib.cpp:4234
OSSTATUS UDFReadAndProcessFullToc(PDEVICE_OBJECT DeviceObject, PVCB Vcb)
Definition: phys_lib.cpp:2243
#define fms
OSSTATUS UDFUseStandard(PDEVICE_OBJECT DeviceObject, PVCB Vcb)
Definition: phys_lib.cpp:2386
OSSTATUS UDFReadDiscTrackInfo(PDEVICE_OBJECT DeviceObject, PVCB Vcb)
Definition: phys_lib.cpp:1635
OSSTATUS UDFGetBlockSize(IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb)
Definition: phys_lib.cpp:2687
#define _SEH2_FINALLY
Definition: pseh2_64.h:114
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define max(a, b)
Definition: svc.c:63
#define UDF_VCB_IC_SYNCCACHE_BEFORE_READ
Definition: udf_common.h:512
#define UDF_VCB_FLAGS_USE_CAV
Definition: udf_common.h:487
#define UDF_VCB_FLAGS_VOLUME_READ_ONLY
Definition: udf_common.h:463
#define UDF_VCB_FLAGS_RAW_DISK
Definition: udf_common.h:476
#define UDF_VCB_IC_NO_SYNCCACHE_AFTER_WRITE
Definition: udf_common.h:507
#define UDF_VCB_FLAGS_FORCE_SYNC_CACHE
Definition: udf_common.h:485
#define UDF_VCB_IC_MRW_ADDR_PROBLEM
Definition: udf_common.h:510
#define UDF_VCB_IC_BAD_DVD_LAST_LBA
Definition: udf_common.h:511
#define UDF_VCB_IC_FP_ADDR_PROBLEM
Definition: udf_common.h:509
#define UDF_VCB_IC_BAD_RW_SEEK
Definition: udf_common.h:508
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define MKUDF_CANT_APPLY_R
Definition: udferr_usr.h:79
#define MKUDF_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:56
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFPrepareForReadOperation()

OSSTATUS UDFPrepareForReadOperation ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BCount 
)

Definition at line 3670 of file phys_lib.cpp.

3675{
3676 if( (Vcb->FsDeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM) ) {
3677 Vcb->VCBFlags &= ~UDF_VCB_LAST_WRITE;
3678 return STATUS_SUCCESS;
3679 }
3680 uint32 i = Vcb->LastReadTrack;
3681 BOOLEAN speed_changed = FALSE;
3682#ifdef _BROWSE_UDF_
3683 PUCHAR tmp;
3684 OSSTATUS RC;
3686#endif //_BROWSE_UDF_
3687
3688#ifdef _UDF_STRUCTURES_H_
3689 if(Vcb->BSBM_Bitmap) {
3690 ULONG i;
3691 for(i=0; i<BCount; i++) {
3692 if(UDFGetBit((uint32*)(Vcb->BSBM_Bitmap), Lba+i)) {
3693 UDFPrint(("R: Known BB @ %#x\n", Lba));
3694 //return STATUS_FT_WRITE_RECOVERY; // this shall not be treated as error and
3695 // we shall get IO request to BAD block
3697 }
3698 }
3699 }
3700#endif //_UDF_STRUCTURES_H_
3701
3702 if(!UDFIsDvdMedia(Vcb) &&
3703 (Vcb->VCBFlags & UDF_VCB_LAST_WRITE) &&
3704 !(Vcb->VCBFlags & UDF_VCB_FLAGS_NO_SYNC_CACHE) &&
3705 !(Vcb->CompatFlags & UDF_VCB_IC_NO_SYNCCACHE_AFTER_WRITE)){
3706
3707// OSSTATUS RC;
3708
3709 RC = UDFSyncCache(Vcb);
3710 }
3711 if( (Vcb->VCBFlags & UDF_VCB_LAST_WRITE) &&
3712 !(Vcb->VCBFlags & UDF_VCB_FLAGS_NO_SYNC_CACHE) &&
3713#ifndef UDF_FORMAT_MEDIA
3714 (Vcb->CompatFlags & UDF_VCB_IC_SYNCCACHE_BEFORE_READ) &&
3715#endif //UDF_FORMAT_MEDIA
3716 TRUE)
3717 {
3718// OSSTATUS RC;
3720 }
3721
3722#ifdef _BROWSE_UDF_
3723 if(!UDFIsDvdMedia(Vcb)) {
3724 // limit read speed after write operation
3725 // to avoid performance degrade durring speed-up/down
3726 // on read/write mode switching
3727 if(Vcb->VCBFlags & UDF_VCB_FLAGS_USE_CAV) {
3728 // limit both read & write speed to last write speed for CAV mode
3729 // some drives damage data when speed is adjusted during recording process
3730 // even in packet mode
3731 if(Vcb->CurSpeed != Vcb->MaxWriteSpeed ||
3732 Vcb->CurSpeed != Vcb->MaxReadSpeed) {
3733 Vcb->CurSpeed = Vcb->MaxWriteSpeed;
3734 speed_changed = TRUE;
3735 }
3736 } else
3737 if(Vcb->VCBFlags & UDF_VCB_LAST_WRITE) {
3738 // limit read speed to last write speed
3739 if(Vcb->CurSpeed > Vcb->MaxWriteSpeed) {
3740 Vcb->CurSpeed = Vcb->MaxWriteSpeed;
3741 speed_changed = TRUE;
3742 }
3743 } else
3744 if(Vcb->CurSpeed < Vcb->MaxReadSpeed ) {
3745 // increment read speed (+1X)
3746 Vcb->CurSpeed += 176/1;
3747 speed_changed = TRUE;
3748 }
3749
3750 if(Vcb->CurSpeed > Vcb->MaxReadSpeed) {
3751 Vcb->CurSpeed = Vcb->MaxReadSpeed;
3752 }
3753 // send speed limits to drive
3754 if(speed_changed) {
3755 RtlZeroMemory(&(Vcb->SpeedBuf), sizeof(SET_CD_SPEED_EX_USER_IN));
3756 Vcb->SpeedBuf.ReadSpeed = Vcb->CurSpeed;
3757 Vcb->SpeedBuf.WriteSpeed = Vcb->MaxWriteSpeed;
3758 if(Vcb->VCBFlags & UDF_VCB_FLAGS_USE_CAV) {
3759 Vcb->SpeedBuf.RotCtrl = CdSpeed_RotCtrl_CAV;
3760 }
3761 UDFPrint((" UDFPrepareForReadOperation: set speed to %s %dX/%dX\n",
3762 (Vcb->VCBFlags & UDF_VCB_FLAGS_USE_CAV) ? "CAV" : "CLV",
3763 Vcb->SpeedBuf.ReadSpeed,
3764 Vcb->SpeedBuf.WriteSpeed));
3766 Vcb->TargetDeviceObject,
3767 &(Vcb->SpeedBuf),sizeof(SET_CD_SPEED_EX_USER_IN),
3768 NULL,0,TRUE,NULL);
3769 }
3770 }
3771
3772 if(UDFIsDvdMedia(Vcb))
3773 return STATUS_SUCCESS;
3774
3775 if(Vcb->LastReadTrack &&
3776 ((Vcb->TrackMap[i].FirstLba <= Lba) || (Vcb->TrackMap[i].FirstLba & 0x80000000)) &&
3777 (Vcb->TrackMap[i].LastLba >= Lba)) {
3778check_for_data_track:
3779 // check track mode (Mode1/XA)
3780 switch((Vcb->TrackMap[i].DataParam & TrkInfo_Dat_Mask)) {
3781 case TrkInfo_Dat_Mode1: // Mode1
3782 case TrkInfo_Dat_XA: // XA Mode2
3783 case TrkInfo_Dat_Unknown: // for some stupid irons
3785 break;
3786 default:
3787 Vcb->IncrementalSeekState = INCREMENTAL_SEEK_NONE;
3789 }
3790 } else {
3791 for(i=Vcb->FirstTrackNum; i<=Vcb->LastTrackNum; i++) {
3792 if(((Vcb->TrackMap[i].FirstLba > Lba) && !(Vcb->TrackMap[i].FirstLba & 0x80000000)) ||
3793 (Vcb->TrackMap[i].LastLba < Lba))
3794 continue;
3795 Vcb->LastReadTrack = i;
3796 goto check_for_data_track;
3797 }
3798 Vcb->LastReadTrack = 0;
3799 }
3800 if(Vcb->IncrementalSeekState != INCREMENTAL_SEEK_WORKAROUND) {
3801 Vcb->IncrementalSeekState = INCREMENTAL_SEEK_NONE;
3802 return STATUS_SUCCESS;
3803 }
3804 UDFPrint((" UDFPrepareForReadOperation: seek workaround...\n"));
3805 Vcb->IncrementalSeekState = INCREMENTAL_SEEK_DONE;
3806
3807 tmp = (PUCHAR)DbgAllocatePoolWithTag(NonPagedPool, Vcb->BlockSize, 'bNWD');
3808 if(!tmp) {
3809 Vcb->IncrementalSeekState = INCREMENTAL_SEEK_NONE;
3811 }
3812 for(i=0x1000; i<=Lba; i+=0x1000) {
3813 RC = UDFPhReadSynchronous(Vcb->TargetDeviceObject, tmp, Vcb->BlockSize,
3814 ((uint64)UDFFixFPAddress(Vcb,i)) << Vcb->BlockSizeBits, &ReadBytes, 0);
3815 UDFPrint((" seek workaround, LBA %x, status %x\n", i, RC));
3816 }
3817 DbgFreePool(tmp);
3818#endif //_BROWSE_UDF_
3819
3820 return STATUS_SUCCESS;
3821} // end UDFPrepareForReadOperation()
unsigned char BOOLEAN
#define TrkInfo_Dat_Unknown
Definition: cdrw_hw.h:2416
#define TrkInfo_Dat_XA
Definition: cdrw_hw.h:2413
#define TrkInfo_Dat_Mode1
Definition: cdrw_hw.h:2411
#define CdSpeed_RotCtrl_CAV
Definition: cdrw_hw.h:594
#define TrkInfo_Dat_Mask
Definition: cdrw_hw.h:2410
unsigned long long uint64
Definition: platform.h:18
NTSTATUS NTAPI UDFPhReadSynchronous(PDEVICE_OBJECT DeviceObject, PVOID Buffer, SIZE_T Length, LONGLONG Offset, PSIZE_T ReadBytes, ULONG Flags)
Definition: env_spec.cpp:130
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
#define DbgFreePool
Definition: env_spec_w32.h:334
NTSTATUS UDFSetMRWMode(IN PVCB Vcb)
Definition: phys_lib.cpp:811
NTSTATUS UDFSyncCache(IN PVCB Vcb)
Definition: phys_lib.cpp:52
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:48
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
#define INCREMENTAL_SEEK_DONE
Definition: udf_common.h:303
#define INCREMENTAL_SEEK_WORKAROUND
Definition: udf_common.h:302
#define UDF_VCB_FLAGS_NO_SYNC_CACHE
Definition: udf_common.h:467
#define UDF_VCB_LAST_WRITE
Definition: udf_common.h:472
#define INCREMENTAL_SEEK_NONE
Definition: udf_common.h:301
#define UDFGetBit(arr, bit)
Definition: udf_info.h:1180
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

Referenced by UDFTRead().

◆ UDFPrepareForWriteOperation()

OSSTATUS UDFPrepareForWriteOperation ( IN PVCB  Vcb,
IN ULONG  Lba,
IN ULONG  BCount 
)

Definition at line 893 of file phys_lib.cpp.

898{
899#ifndef UDF_READ_ONLY_BUILD
900#ifdef UDF_FORMAT_MEDIA
901 PUDFFmtState fms = Vcb->fms;
902#else
903 #define fms FALSE
904#endif //UDF_FORMAT_MEDIA
905
906#ifdef _UDF_STRUCTURES_H_
907 if(Vcb->BSBM_Bitmap) {
908 ULONG i;
909 for(i=0; i<BCount; i++) {
910 if(UDFGetBit((uint32*)(Vcb->BSBM_Bitmap), Lba+i)) {
911 UDFPrint(("W: Known BB @ %#x\n", Lba));
912 //return STATUS_FT_WRITE_RECOVERY; // this shall not be treated as error and
913 // we shall get IO request to BAD block
915 }
916 }
917 }
918#endif //_UDF_STRUCTURES_H_
919
920 Vcb->VCBFlags |= UDF_VCB_LAST_WRITE;
921
922 if(
923#ifdef _BROWSE_UDF_
924 (((Vcb->FsDeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
925 !(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_MOUNTED) ||
926 (Vcb->VCBFlags & UDF_VCB_FLAGS_RAW_DISK))
927 && !fms
928 ) ||
929#endif //_BROWSE_UDF_
930#ifdef UDF_FORMAT_MEDIA
931 (fms && fms->SkipPrepareW) ||
932#endif //UDF_FORMAT_MEDIA
934 ) {
935 UDFPrint(("Skip prepare for Write @%x\n", Lba));
936 return STATUS_SUCCESS;
937 }
938
939 // check if the device requires OPC before each write operation
940 UDFDoOPC(Vcb);
941
942 if(Vcb->SyncCacheState == SYNC_CACHE_RECOVERY_ATTEMPT) {
943 Vcb->SyncCacheState = SYNC_CACHE_RECOVERY_RETRY;
944 } else {
945 Vcb->SyncCacheState = SYNC_CACHE_RECOVERY_NONE;
946 }
947 if(Vcb->LastModifiedTrack &&
948 (Vcb->TrackMap[Vcb->LastModifiedTrack].FirstLba <= Lba) &&
949 (Vcb->TrackMap[Vcb->LastModifiedTrack].LastLba >= Lba) &&
950 !( (Vcb->MediaClassEx == CdMediaClass_DVDRW ||
951 Vcb->MediaClassEx == CdMediaClass_DVDpRW ||
952 Vcb->MediaClassEx == CdMediaClass_DVDRAM ||
953 Vcb->MRWStatus == DiscInfo_BGF_Interrupted ||
954 Vcb->MRWStatus == DiscInfo_BGF_InProgress) && (Lba > Vcb->LastLBA))
955 ) {
956 // Ok, we needn't change Write Parameters
957// if(Vcb->TrackMap[Vcb->LastModifiedTrack].Flags & TrackMap_Try_variation)
958// Vcb->TrackMap[Vcb->LastModifiedTrack].Flags |= TrackMap_Use_variation;
959 UDFPrint(("Skip prepare for Write (2) @%x\n", Lba));
960 return STATUS_SUCCESS;
961 }
962
964
966#ifdef UDF_FORMAT_MEDIA
967 if(fms) {
968 return STATUS_SUCCESS;
969 }
970#endif //UDF_FORMAT_MEDIA
971 }
972
973 for(uint32 i=Vcb->FirstTrackNum; i<=Vcb->LastTrackNum; i++) {
974 if((Vcb->TrackMap[i].FirstLba > Lba) ||
975 (Vcb->TrackMap[i].LastLba < Lba)) {
976 //UDFPrint(("not in track %d\n"));
977 continue;
978 }
979 OSSTATUS RC;
981
983 RC = STATUS_SUCCESS;
984 goto check_dvd_bg_format;
985 }
986
987 if(!Vcb->WParams) {
988 Vcb->WParams =
990 }
991 if(!(WParams = Vcb->WParams)) {
992 UDFPrint(("!WParams\n"));
994 }
995
996 RC = UDFPhSendIOCTL(IOCTL_CDRW_GET_WRITE_MODE, Vcb->TargetDeviceObject,
997 NULL,0,
998 (void*)(Vcb->WParams),sizeof(GET_WRITE_MODE_USER_OUT),
999 FALSE, NULL);
1000 if(!OS_SUCCESS(RC)) {
1001#ifdef UDF_FORMAT_MEDIA
1002 if(fms) {
1003 fms->SkipPrepareW = 1;
1004 MyFreePool__(WParams);
1005 return STATUS_SUCCESS;
1006 }
1007#endif //UDF_FORMAT_MEDIA
1008 UDFPrint(("!get WParams\n"));
1009 return RC;
1010 }
1011 // clear unnecassary flags
1012 WParams->Byte2.Flags &= ~WParam_TestWrite;
1013 WParams->Byte2.Flags &= ~WParam_WType_Mask;
1014 // select packet writing
1015 WParams->Byte2.Flags |= WParam_WType_Packet;
1016
1017 WParams->Byte3.Flags &= ~(WParam_TrkMode_Mask |
1019 WParam_Copy);
1020 WParams->Byte3.Flags |= Vcb->TrackMap[i].TrackParam &
1023 WParam_Copy);
1024
1025 // set packet type (VP/FP)
1026// if(opt_partition == PT_VAT15 ||
1027// opt_blank_vat15)
1028 if(WParams->Byte2.Flags & WParam_LS_V) {
1029 WParams->LinkSize = 7;
1030 }
1031
1032 if(Vcb->TrackMap[i].DataParam & TrkInfo_Packet) {
1033 if((Vcb->TrackMap[i].DataParam & TrkInfo_FP) &&
1034 !Vcb->CDR_Mode) {
1035 WParams->Byte3.Flags |= WParam_FP;
1036 } else {
1037 WParams->Byte3.Flags &= ~WParam_FP;
1038 }
1039 } else {
1040 if(!Vcb->CDR_Mode) {
1041 WParams->Byte3.Flags |= WParam_FP;
1042 } else {
1043 WParams->Byte3.Flags &= ~WParam_FP;
1044 }
1045 }
1046
1047 // select multisession mode
1048 WParams->Byte3.Flags &= ~WParam_MultiSes_Mask;
1049 if((Vcb->DiscStat & DiscInfo_Disk_Mask) == DiscInfo_Disk_Appendable) {
1050 WParams->Byte3.Flags |= WParam_Multises_Multi;
1051 } else
1052 if(Vcb->LastSession > 1) {
1053 WParams->Byte3.Flags |= WParam_Multises_Final;
1054 } else {
1055 WParams->Byte3.Flags |= WParam_Multises_None;
1056 }
1057 // set sector mode (Mode1/XA)
1058 WParams->Byte4.Flags &= ~WParam_BlkType_Mask;
1059 if((Vcb->TrackMap[i].DataParam & TrkInfo_Dat_Mask) == TrkInfo_Dat_XA) {
1060 // XA Mode2
1062 WParams->SesFmt = WParam_SesFmt_CdRomXa;
1063 } else if((Vcb->TrackMap[i].DataParam & TrkInfo_Dat_Mask) == TrkInfo_Dat_Mode1) {
1064 // Mode1
1066 WParams->SesFmt = WParam_SesFmt_CdRom;
1067 } else {
1068#ifdef UDF_FORMAT_MEDIA
1069 if(fms) {
1070 fms->SkipPrepareW = 1;
1071 MyFreePool__(WParams);
1072 return STATUS_SUCCESS;
1073 }
1074#endif //UDF_FORMAT_MEDIA
1075 UDFPrint((" inv sector mode\n"));
1077 }
1078 // set packet size
1079 *((uint32*)&(WParams->PacketSize)) = BCount;
1080 *((uint32*)&(WParams->SubHeader)) = 0;
1081 // set additional flags for VP
1082
1083 if(Vcb->CDR_Mode) {
1084// if(opt_partition == PT_VAT15)
1085 WParams->SubHeader.Params.Params1.SubMode = WParam_SubHdr_SubMode1;
1086 }
1087 WParams->PageLength = sizeof(GET_WRITE_MODE_USER_OUT)-2;
1089 // apply write parameters
1090 RC = UDFPhSendIOCTL(IOCTL_CDRW_SET_WRITE_MODE, Vcb->TargetDeviceObject,
1091 (void*)WParams,sizeof(SET_WRITE_MODE_USER_IN),
1092 NULL,0,FALSE,NULL);
1093
1094#ifdef UDF_FORMAT_MEDIA
1095 if(fms) {
1096 if(!NT_SUCCESS(RC)) {
1097 fms->SkipPrepareW = 1;
1098 MyFreePool__(WParams);
1099 return STATUS_SUCCESS;
1100 }
1101
1102 RC = UDFPhSendIOCTL(IOCTL_CDRW_GET_WRITE_MODE, Vcb->TargetDeviceObject,
1103 NULL,0,
1104 (PVOID)WParams,sizeof(GET_WRITE_MODE_USER_OUT),
1105 FALSE, NULL);
1106 if(!NT_SUCCESS(RC)) {
1107 MyFreePool__(WParams);
1108 return RC;
1109 }
1110
1111 if(fms->opt_partition == PT_VAT15 ||
1112 fms->opt_blank_vat15) {
1113 if(WParams->Byte3.Flags & WParam_FP) {
1114 MyFreePool__(WParams);
1116 }
1117 } else {
1118 if(!(WParams->Byte3.Flags & WParam_FP)) {
1119 MyFreePool__(WParams);
1121 }
1122 }
1123 }
1124#endif //UDF_FORMAT_MEDIA
1125
1126 // switch to random access mode
1127 ((PSET_RANDOM_ACCESS_USER_IN)WParams)->RandomAccessMode = Vcb->CDR_Mode ? FALSE : TRUE;
1128// ((PSET_RANDOM_ACCESS_USER_IN)WParams)->RandomAccessMode = (opt_partition != PT_VAT15) ? TRUE : FALSE;
1129 RC = UDFPhSendIOCTL(IOCTL_CDRW_SET_RANDOM_ACCESS, Vcb->TargetDeviceObject,
1130 (void*)WParams,sizeof(SET_RANDOM_ACCESS_USER_IN),
1131 NULL,0,FALSE, NULL);
1132
1133check_dvd_bg_format:
1134
1135 UDFPrint((" check BGF\n"));
1136 if(!Vcb->CDR_Mode) {
1137 if(OS_SUCCESS(RC)) {
1138 Vcb->LastModifiedTrack = i;
1139 if(!(Vcb->TrackMap[i].Flags & TrackMap_Use_variation)) {
1140 if(Vcb->TrackMap[i].Flags & TrackMap_Try_variation) {
1141 Vcb->TrackMap[i].Flags |= TrackMap_Use_variation;
1142 } else {
1143 Vcb->TrackMap[i].Flags |= TrackMap_Try_variation;
1144 }
1145 }
1146 }
1147 } else {
1148 Vcb->LastModifiedTrack = 0;
1149 }
1150// fms->SkipPrepareW = 1;
1151
1152
1153 if((Vcb->MediaClassEx == CdMediaClass_DVDRW ||
1154 Vcb->MediaClassEx == CdMediaClass_DVDpRW ||
1155 Vcb->MediaClassEx == CdMediaClass_DVDRAM ||
1156 Vcb->MRWStatus == DiscInfo_BGF_Interrupted )
1157 && (Lba > Vcb->LastLBA)) {
1158
1159 ULONG fLba;
1160 SIZE_T WrittenBytes;
1161 ULONG PSz = BCount << Vcb->BlockSizeBits;
1162#ifdef _BROWSE_UDF_
1163 ULONG retry;
1164#endif //_BROWSE_UDF_
1166
1167 ASSERT((Vcb->LastLBA+1) == Vcb->NWA);
1168
1169 if(Lba+BCount <= (Vcb->LastLBA+1) ) {
1170 UDFPrint(("DVD cont. fmt, LBA+BCount<=NWA, exiting\n"));
1171 return STATUS_SUCCESS;
1172 }
1173 if((Vcb->MRWStatus != DiscInfo_BGF_Interrupted) &&
1174 (Lba <= (Vcb->LastLBA+1)) ) {
1175 UDFPrint(("!PausedBGF + DVD cont. fmt, LBA<=NWA, exiting\n"));
1176 return STATUS_SUCCESS;
1177 }
1178
1179 if(Vcb->MRWStatus == DiscInfo_BGF_Interrupted) {
1180 // This code also can restart background MRW formatting
1181 UDFPrint(("DVD cont. fmt, LastLBA %x, Lba %x\n", Vcb->LastLBA, Lba));
1182
1184 if(ForBuf) {
1186 ForBuf->Flags.FlagsEx = FORMAT_UNIT_RESTART_MRW;
1187 ForBuf->BlockCount = 0xffffffff;
1188
1189 RC = UDFPhSendIOCTL(IOCTL_CDRW_FORMAT_UNIT, Vcb->TargetDeviceObject,
1190 ForBuf,sizeof(FORMAT_CDRW_PARAMETERS_USER_IN),
1191 NULL,0,FALSE, NULL);
1192 DbgFreePool(ForBuf);
1193 if(OS_SUCCESS(RC)) {
1194 UDFPrint(("BGFormat restarted Interrupted->InProgress\n"));
1195 Vcb->MRWStatus = DiscInfo_BGF_InProgress;
1196 } else {
1198 if(!Vcb->Error) {
1199 Vcb->Error = (PGET_LAST_ERROR_USER_OUT)
1201 }
1202 Error = Vcb->Error;
1203 if(Error) {
1204 UDFPhSendIOCTL( IOCTL_CDRW_GET_LAST_ERROR, Vcb->TargetDeviceObject,
1205 NULL,0,
1207 TRUE,NULL);
1208 UDFPrint(("SK=%x ASC=%x, ASCQ=%x, IE=%x\n",
1209 Error->SenseKey, Error->AdditionalSenseCode, Error->AdditionalSenseCodeQualifier, Error->LastError));
1210 // check for Long Write In Progress
1211 if( (Error->SenseKey == SCSI_SENSE_NOT_READY) &&
1212 (Error->AdditionalSenseCode == SCSI_ADSENSE_LUN_NOT_READY) &&
1213 ((Error->AdditionalSenseCodeQualifier == SCSI_SENSEQ_LONG_WRITE_IN_PROGRESS) ||
1214 (Error->AdditionalSenseCodeQualifier == SCSI_SENSEQ_FORMAT_IN_PROGRESS)) ) {
1215 RC = STATUS_SUCCESS;
1216 UDFPrint(("Seems, BGFormat already restarted\n"));
1217 Vcb->MRWStatus = DiscInfo_BGF_InProgress;
1218 }
1219 }
1220 }
1221 }
1222 } else {
1223 RC = STATUS_SUCCESS;
1224 }
1225
1226 UDFPrint(("DVD cont. write, LastLBA %x, Lba %x\n", Vcb->LastLBA, Lba));
1227
1228 ASSERT(Vcb->MediaClassEx == CdMediaClass_DVDRW);
1229 if(!Vcb->fZBuffer) {
1230 Vcb->fZBuffer = (PCHAR)DbgAllocatePoolWithTag(NonPagedPool, PSz, 'zNWD');
1231 RtlZeroMemory(Vcb->fZBuffer, PSz);
1232 Vcb->fZBufferSize = PSz;
1233 } else
1234 if(Vcb->fZBufferSize < PSz) {
1235 PSz = Vcb->fZBufferSize;
1236 }
1237 if(!Vcb->fZBuffer) {
1238 BrutePoint();
1240 } else {
1241 for(fLba = Vcb->NWA; fLba < Lba; fLba+=BCount) {
1242#ifdef _BROWSE_UDF_
1243 retry = UDF_WRITE_MAX_RETRY;
1244retry_1:
1245#endif //_BROWSE_UDF_
1246 RC = UDFPhWriteVerifySynchronous(Vcb->TargetDeviceObject, Vcb->fZBuffer, PSz,
1247 ((uint64)fLba) << Vcb->BlockSizeBits, &WrittenBytes, PH_TMP_BUFFER);
1248 Vcb->VCBFlags |= UDF_VCB_SKIP_EJECT_CHECK;
1249 UDFPrint(("Fmt status: %x\n", RC));
1250#ifdef _BROWSE_UDF_
1251 if(!OS_SUCCESS(RC) &&
1252 OS_SUCCESS(RC = UDFRecoverFromError(Vcb, TRUE, RC, fLba, BCount, &retry)) ) {
1253 goto retry_1;
1254 UDFPrint(("Fmt retry\n"));
1255 }
1256#endif //_BROWSE_UDF_
1257 if(!OS_SUCCESS(RC)) {
1258 BrutePoint();
1259 UDFPrint(("Fmt break on ERROR\n"));
1260 break;
1261 }
1262 UDFUpdateNWA(Vcb, fLba, BCount, RC);
1263 }
1264 }
1265 } else {
1266 UDFPrint((" no special processing\n"));
1267 }
1268
1269 return RC;
1270 }
1271#endif //UDF_READ_ONLY_BUILD
1272 UDFPrint((" no suitable track!\n"));
1274} // end UDFPrepareForWriteOperation()
BOOL Error
Definition: chkdsk.c:66
#define SCSI_ADSENSE_LUN_NOT_READY
Definition: cdrw_hw.h:1218
#define WParam_Multises_None
Definition: cdrw_hw.h:2651
#define WParam_SesFmt_CdRom
Definition: cdrw_hw.h:2698
#define WParam_TrkMode_AllowCpy
Definition: cdrw_hw.h:2647
#define WParam_SesFmt_CdRomXa
Definition: cdrw_hw.h:2700
#define DiscInfo_Disk_Appendable
Definition: cdrw_hw.h:2272
#define WParam_LS_V
Definition: cdrw_hw.h:2626
#define WParam_Copy
Definition: cdrw_hw.h:2648
#define WParam_TrkMode_Mask
Definition: cdrw_hw.h:2640
#define WParam_Multises_Final
Definition: cdrw_hw.h:2652
#define TrkInfo_Packet
Definition: cdrw_hw.h:2418
#define MODE_PAGE_WRITE_PARAMS
Definition: cdrw_hw.h:844
#define DiscInfo_BGF_InProgress
Definition: cdrw_hw.h:2301
#define WParam_SubHdr_SubMode1
Definition: cdrw_hw.h:2730
#define WParam_BlkType_M2XAF1_2048
Definition: cdrw_hw.h:2673
#define WParam_WType_Packet
Definition: cdrw_hw.h:2621
#define WParam_Multises_Multi
Definition: cdrw_hw.h:2653
#define DiscInfo_BGF_Interrupted
Definition: cdrw_hw.h:2300
#define WParam_BlkType_M1_2048
Definition: cdrw_hw.h:2671
#define DiscInfo_Disk_Mask
Definition: cdrw_hw.h:2270
#define SCSI_SENSE_NOT_READY
Definition: cdrw_hw.h:1189
#define SCSI_SENSEQ_FORMAT_IN_PROGRESS
Definition: cdrw_hw.h:1316
#define SCSI_SENSEQ_LONG_WRITE_IN_PROGRESS
Definition: cdrw_hw.h:1318
#define WParam_FP
Definition: cdrw_hw.h:2649
struct _FORMAT_CDRW_PARAMETERS_USER_IN * PFORMAT_CDRW_PARAMETERS_USER_IN
#define IOCTL_CDRW_GET_WRITE_MODE
Definition: cdrw_usr.h:85
struct _SET_RANDOM_ACCESS_USER_IN * PSET_RANDOM_ACCESS_USER_IN
#define IOCTL_CDRW_SET_RANDOM_ACCESS
Definition: cdrw_usr.h:99
MODE_WRITE_PARAMS_PAGE_USER GET_WRITE_MODE_USER_OUT
Definition: cdrw_usr.h:1010
#define IOCTL_CDRW_SET_WRITE_MODE
Definition: cdrw_usr.h:86
#define TrackMap_Use_variation
Definition: cdrw_usr.h:1640
PMODE_WRITE_PARAMS_PAGE_USER PGET_WRITE_MODE_USER_OUT
Definition: cdrw_usr.h:1011
#define TrackMap_Try_variation
Definition: cdrw_usr.h:1639
struct _GET_LAST_ERROR_USER_OUT * PGET_LAST_ERROR_USER_OUT
#define IOCTL_CDRW_GET_LAST_ERROR
Definition: cdrw_usr.h:103
#define IOCTL_CDRW_FORMAT_UNIT
Definition: cdrw_usr.h:98
#define FORMAT_UNIT_RESTART_MRW
Definition: cdrw_usr.h:516
#define UDFPhWriteVerifySynchronous
Definition: env_spec.h:46
#define BrutePoint()
Definition: env_spec_w32.h:504
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
void UDFUpdateNWA(PVCB Vcb, uint32 LBA, uint32 BCount, OSSTATUS RC)
Definition: phys_lib.cpp:3826
OSSTATUS UDFRecoverFromError(IN PVCB Vcb, IN BOOLEAN WriteOp, IN OSSTATUS status, IN uint32 Lba, IN uint32 BCount, IN OUT uint32 *retry)
Definition: phys_lib.cpp:1283
OSSTATUS UDFDoOPC(IN PVCB Vcb)
Definition: phys_lib.cpp:850
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
#define _BROWSE_UDF_
Definition: struct.h:330
union _MODE_WRITE_PARAMS_PAGE_USER::@946 Byte4
union _MODE_WRITE_PARAMS_PAGE_USER::@945 Byte3
union _MODE_WRITE_PARAMS_PAGE_USER::@944 Byte2
struct _MODE_WRITE_PARAMS_PAGE_USER::@948 SubHeader
#define UDFIsWriteParamsReq(Vcb)
Definition: udf_common.h:525
#define UDF_VCB_FLAGS_VOLUME_MOUNTED
Definition: udf_common.h:459
#define SYNC_CACHE_RECOVERY_ATTEMPT
Definition: udf_common.h:278
#define SYNC_CACHE_RECOVERY_NONE
Definition: udf_common.h:277
#define SYNC_CACHE_RECOVERY_RETRY
Definition: udf_common.h:279
#define UDF_VCB_SKIP_EJECT_CHECK
Definition: udf_common.h:470
#define UDF_WRITE_MAX_RETRY
Definition: udf_rel.h:502
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178

Referenced by UDFRecoverFromError(), and UDFTWrite().

◆ UDFReadAndProcessFullToc()

OSSTATUS UDFReadAndProcessFullToc ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb 
)

Definition at line 2243 of file phys_lib.cpp.

2247{
2250 uint32 index;
2251 uint8 POINT;
2252 uint8 CurTrack = 0;
2253 uint32 LastLeadOut = 0;
2254// BOOLEAN IsMRW = FALSE;
2255
2256 UDFPrint(("UDFReadAndProcessFullToc\n"));
2257
2258 if(!toc) return STATUS_INSUFFICIENT_RESOURCES;
2259 Vcb->FirstTrackNum = 0xFF;
2260
2262
2264 NULL,0,
2265 toc,sizeof(READ_FULL_TOC_USER_OUT),
2266 TRUE,NULL);
2267
2268 if(!OS_SUCCESS(RC)) {
2269
2270 MyFreePool__(toc);
2271 return RC;
2272 }
2273
2274#ifdef _CONSOLE
2275 Vcb->PhDeviceType = FILE_DEVICE_CD_ROM;
2276#endif //_CONSOLE
2277 Vcb->LastSession = toc->Sessions.Last_TrackSes;
2278
2279 RC = UDFReallocTrackMap(Vcb, 0x100);
2280 if(!OS_SUCCESS(RC)) {
2281 MyFreePool__(toc);
2282 return RC;
2283 }
2284
2285 // get LastPossibleLBA
2286
2287 // Note: some drives return Full TOC items unordered.
2288 // So, LeadOut position may come before Track definition.
2289 // In order to handle such situation, we must initialize
2290 // CurTrack when First or Last Track descriptor comes
2292/* if((toc->SessionData[index].Adr == TOC_ADR_TrackInfo) &&
2293 ((toc->SessionData[index].Control == TOC_CTL_MRWTrackInfo) || (toc->SessionData[index].Control == TOC_CTL_MRWLastSes))) {
2294 IsMRW = TRUE;
2295 }*/
2296 if(toc->SessionData[index].Adr == 1) {
2297 switch (POINT = toc->SessionData[index].POINT) {
2298 case POINT_FirstTrackNum: {
2299 Vcb->FirstTrackNum = toc->SessionData[index].Params.FirstTrackNum.FirstTrackNum;
2300 if(!CurTrack)
2301 CurTrack = (uint8)(Vcb->FirstTrackNum);
2302 break;
2303 }
2304 case POINT_LastTrackNum: {
2305 Vcb->LastTrackNum = toc->SessionData[index].Params.LastTrackNum.LastTrackNum;
2306 if(CurTrack < Vcb->LastTrackNum)
2307 CurTrack = (uint8)(Vcb->FirstTrackNum);
2308 break;
2309 }
2311#define TempMSF toc->SessionData[index].Params.StartPositionOfLeadOut.MSF
2312 Vcb->TrackMap[CurTrack].LastLba = MSF_TO_LBA(TempMSF[0],TempMSF[1],TempMSF[2]);
2313 LastLeadOut = max(LastLeadOut, Vcb->TrackMap[CurTrack].LastLba);
2314#undef TempMSF
2315 break;
2316 }
2317 default: {
2318 if( (Vcb->FirstTrackNum != 0x0FF) &&
2319 (toc->SessionData[index].POINT == Vcb->FirstTrackNum) ) {
2320#define TempMSF toc->SessionData[index].Params.StartPositionOfTrack.MSF
2321 Vcb->FirstLBA = MSF_TO_LBA(TempMSF[0],TempMSF[1],TempMSF[2]);
2322 if(Vcb->FirstLBA & 0x80000000) {
2323 Vcb->FirstLBA = 0;
2324 }
2325#undef TempMSF
2326 }
2327 break;
2328 }
2329 }
2332#define TempMSF toc->SessionData[index].Params.StartPositionOfTrack.MSF
2333 Vcb->TrackMap[POINT].FirstLba = MSF_TO_LBA(TempMSF[0],TempMSF[1],TempMSF[2])-1;
2334 if(Vcb->TrackMap[POINT].FirstLba & 0x80000000) {
2335 if(POINT == 1) {
2336 Vcb->TrackMap[POINT].FirstLba = 0;
2337 } else {
2338 if(Vcb->TrackMap[POINT-1].LastLba) {
2339 Vcb->TrackMap[POINT].FirstLba = Vcb->TrackMap[POINT-1].LastLba+1;
2340 }
2341 }
2342 }
2343#undef TempMSF
2345 Vcb->TrackMap[POINT-1].LastLba = Vcb->TrackMap[POINT].FirstLba-1;
2346 }
2347 CurTrack = POINT;
2348 }
2349 } else
2350 if(toc->SessionData[index].Adr == 5) {
2351 switch (POINT = toc->SessionData[index].POINT) {
2353#define TempMSF toc->SessionData[index].Params.StartPositionOfNextProgramArea.MaxLeadOut_MSF
2354 Vcb->LastPossibleLBA = MSF_TO_LBA(TempMSF[0],TempMSF[1],TempMSF[2]);
2355#undef TempMSF
2356 break;
2357 }
2358 default: {
2359 break;
2360 }
2361 }
2362 }
2363
2364 }
2365
2366/* if(!IsMRW) {
2367 UDFPrint(("No MRW\n"));
2368 Vcb->CompatFlags &= ~UDF_VCB_IC_MRW_ADDR_PROBLEM;
2369 }*/
2370// Vcb->CompatFlags &= ~UDF_VCB_IC_MRW_ADDR_PROBLEM;
2371 // some devices report LastTrackNum=0 for full disks
2372 Vcb->LastTrackNum = max(Vcb->LastTrackNum, Vcb->FirstTrackNum);
2373 Vcb->TrackMap[Vcb->LastTrackNum].LastLba = max(LastLeadOut, Vcb->TrackMap[Vcb->LastTrackNum].LastLba);
2374
2375 Vcb->LastLBA = Vcb->TrackMap[Vcb->LastTrackNum].LastLba;
2376
2377 MyFreePool__(toc);
2378// Vcb->LastLBA=PacketVariable2Fixed(Vcb->LastLBA)-2;
2379 return STATUS_SUCCESS;
2380} // end UDFReadAndProcessFullToc()
#define index(s, c)
Definition: various.h:29
#define POINT_FirstTrackNum
Definition: cdrw_hw.h:1560
#define POINT_LastTrackNum
Definition: cdrw_hw.h:1561
#define POINT_StartPositionOfTrack_Min
Definition: cdrw_hw.h:1558
#define POINT_StartPositionOfNextProgramArea
Definition: cdrw_hw.h:1566
#define POINT_StartPositionOfTrack_Max
Definition: cdrw_hw.h:1559
#define POINT_StartPositionOfLeadOut
Definition: cdrw_hw.h:1562
#define MAXIMUM_NUMBER_OF_SESSIONS
Definition: cdrw_hw.h:835
PREAD_TOC_FULL_TOC PREAD_FULL_TOC_USER_OUT
Definition: cdrw_usr.h:1385
#define IOCTL_CDRW_READ_FULL_TOC
Definition: cdrw_usr.h:113
#define MSF_TO_LBA(Minutes, Seconds, Frames)
Definition: tools.h:269
GLuint index
Definition: glext.h:6031
OSSTATUS UDFReallocTrackMap(IN PVCB Vcb, IN uint32 TrackNum)
Definition: phys_lib.cpp:69
#define TempMSF
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:47
READ_TOC_HEADER Sessions
Definition: cdrw_hw.h:1688
TOC_SES_INFO SessionData[MAXIMUM_NUMBER_OF_SESSIONS]
Definition: cdrw_hw.h:1689
UCHAR Last_TrackSes
Definition: cdrw_hw.h:1528
UCHAR POINT
Definition: cdrw_hw.h:1584
UCHAR FirstTrackNum
Definition: cdrw_hw.h:1619
union _TOC_SES_INFO::@810 Params
UCHAR LastTrackNum
Definition: cdrw_hw.h:1628
#define POINT
Definition: precomp.h:30

Referenced by UDFGetDiskInfo().

◆ UDFReadData()

OSSTATUS UDFReadData ( IN PVCB  Vcb,
IN BOOLEAN  Translate,
IN LONGLONG  Offset,
IN ULONG  Length,
IN BOOLEAN  Direct,
OUT PCHAR  Buffer,
OUT PSIZE_T  ReadBytes 
)

◆ UDFReadDiscTrackInfo()

OSSTATUS UDFReadDiscTrackInfo ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb 
)

Definition at line 1635 of file phys_lib.cpp.

1639{
1643 PTRACK_INFO_BLOCK_USER_IN TrackInfoIn = (PTRACK_INFO_BLOCK_USER_IN)TrackInfoOut;
1644 READ_CAPACITY_USER_OUT CapacityBuffer;
1645 LONG TrackNumber;
1646 BOOLEAN NotFP = FALSE;
1647 BOOLEAN ForceFP = FALSE;
1648 BOOLEAN PacketTrack = FALSE;
1649 BOOLEAN MRWRetry = FALSE;
1650// BOOLEAN ReadCapacityOk = FALSE;
1651#ifdef UDF_FORMAT_MEDIA
1652 PUDFFmtState fms = Vcb->fms;
1653#endif
1654
1655 _SEH2_TRY {
1656 if(!DiscInfo || !TrackInfoOut)
1658
1659MRWRetry_label:
1660
1662 NULL, 0,
1663 DiscInfo,sizeof(DISC_INFO_BLOCK_USER_OUT), TRUE, NULL);
1664 if(!OS_SUCCESS(RC)) {
1665 UDFPrint(("ReadDiskInfo failed. Use default.\n"));
1666 if(Vcb->MediaClassEx == CdMediaClass_DVDRW ||
1667 Vcb->MediaClassEx == CdMediaClass_DVDpRW ||
1668 Vcb->MediaClassEx == CdMediaClass_DVDRAM) {
1669 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_DVD;
1670 } else
1671 if(Vcb->MediaClassEx == CdMediaClass_BDRE) {
1672 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_BD;
1673 } else {
1674 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_FP_CD;
1675 }
1676 try_return(RC);
1677 }
1678#ifdef UDF_FORMAT_MEDIA
1679 if(fms && fms->opt_disk_info) {
1680 UserPrint(("ReadDiskInfo OK\n"));
1681 }
1682#endif //UDF_FORMAT_MEDIA
1683
1685 NULL, 0,
1686 &CapacityBuffer,sizeof(READ_CAPACITY_USER_OUT), TRUE, NULL);
1687 if(!OS_SUCCESS(RC)) {
1688 UDFPrint(("ReadCapacity failed.\n"));
1689 if(Vcb->MediaClassEx == CdMediaClass_DVDpRW) {
1690 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_DVD;
1691 }
1692 } else {
1693 UDFPrint(("ReadCapacity ok.\n"));
1694 UDFPrint(("Last possible LBA %#x.\n", CapacityBuffer.LogicalBlockAddress));
1695 if(!(CapacityBuffer.LogicalBlockAddress & 0xc0000000) &&
1696 (CapacityBuffer.LogicalBlockAddress != 0x7fffffff)) {
1697 // good value from ReadCapacity
1698 UDFPrint(("Update Last possible LBA %#x.\n", CapacityBuffer.LogicalBlockAddress));
1699 Vcb->LastPossibleLBA = CapacityBuffer.LogicalBlockAddress;
1700// ReadCapacityOk = TRUE;
1701#ifdef UDF_FORMAT_MEDIA
1702 if(fms && fms->opt_disk_info) {
1703 UserPrint(("ReadCapacity OK\n"));
1704 }
1705#endif //UDF_FORMAT_MEDIA
1706 }
1707 }
1708
1709#ifdef _CONSOLE
1710 Vcb->PhDeviceType = FILE_DEVICE_CD_ROM;
1711#endif //_CONSOLE
1712 Vcb->PhSerialNumber = *((uint32*)&(DiscInfo->DiskId));
1713 Vcb->PhErasable = DiscInfo->DiscStat.Flags & DiscInfo_Disk_Erasable;
1714 Vcb->PhDiskType = DiscInfo->DiskType;
1715 // save OPC info
1716 if(DiscInfo->OPCNum)
1717 Vcb->OPCNum = DiscInfo->OPCNum;
1718 UDFPrint(("DiskInfo: SN %x, OPCn %x(%x), Stat %x, Flg: %x\n",
1719 Vcb->PhSerialNumber, Vcb->OPCNum, DiscInfo->OPCNum, DiscInfo->DiscStat.Flags, DiscInfo->Flags.Flags));
1720#ifdef UDF_FORMAT_MEDIA
1721 if(fms && fms->opt_disk_info) {
1722 UserPrint(("Media type: "));
1723 switch(Vcb->MediaClassEx) {
1724 case CdMediaClass_CDROM : UserPrint(("CD-ROM \n")); break;
1725 case CdMediaClass_CDR : UserPrint(("CD-R \n")); break;
1726 case CdMediaClass_CDRW : UserPrint(("CD-RW \n")); break;
1727 case CdMediaClass_DVDROM : UserPrint(("DVD-ROM \n")); break;
1728 case CdMediaClass_DVDRAM : UserPrint(("DVD-RAM \n")); break;
1729 case CdMediaClass_DVDR : UserPrint(("DVD-R \n")); break;
1730 case CdMediaClass_DVDRW : UserPrint(("DVD-RW \n")); break;
1731 case CdMediaClass_DVDpR : UserPrint(("DVD+R \n")); break;
1732 case CdMediaClass_DVDpRW : UserPrint(("DVD+RW \n")); break;
1733 case CdMediaClass_DDCDROM : UserPrint(("DDCD-ROM \n")); break;
1734 case CdMediaClass_DDCDR : UserPrint(("DDCD-R \n")); break;
1735 case CdMediaClass_DDCDRW : UserPrint(("DDCD-RW \n")); break;
1736 case CdMediaClass_BDROM : UserPrint(("BD-ROM \n")); break;
1737 case CdMediaClass_BDRE : UserPrint(("BD-RE \n")); break;
1738 case CdMediaClass_BDR : UserPrint(("BD-R \n")); break;
1739 case CdMediaClass_HD_DVDROM : UserPrint(("HD DVD-ROM \n")); break;
1740 case CdMediaClass_HD_DVDRAM : UserPrint(("HD DVD-RAM \n")); break;
1741 case CdMediaClass_HD_DVDR : UserPrint(("HD DVD-R \n")); break;
1742 case CdMediaClass_HD_DVDRW : UserPrint(("HD DVD-RW \n")); break;
1743 default: UserPrint(("Unknown\n")); break;
1744 }
1745 UserPrint(("SN %#x, OPCn %#x\n",
1746 Vcb->PhSerialNumber, Vcb->OPCNum, DiscInfo->OPCNum));
1747 UserPrint(("Disk State: "));
1748 switch(DiscInfo->DiscStat.Flags & DiscInfo_Disk_Mask) {
1750 UserPrint(("Empty\n"));
1751 break;
1753 UserPrint(("Appendable\n"));
1754 break;
1756 UserPrint(("Complete\n"));
1757 break;
1759 UserPrint(("RW in unknown state\n"));
1760 break;
1761 }
1762 UserPrint(("Last Session State: "));
1763 switch(DiscInfo->DiscStat.Flags & DiscInfo_Ses_Mask) {
1764 case DiscInfo_Ses_Empty:
1765 UserPrint(("Empty\n"));
1766 break;
1768 UserPrint(("Incomplete\n"));
1769 break;
1771 UserPrint(("Complete\n"));
1772 break;
1773 default:
1774 UserPrint(("unknown state\n"));
1775 break;
1776 }
1777 UserPrint(("Erasable: %s\n",
1778 (DiscInfo->DiscStat.Flags & DiscInfo_Disk_Erasable) ? "yes" : "no"
1779 ));
1780 }
1781#endif //UDF_FORMAT_MEDIA
1782 // Save disk status
1783 Vcb->DiscStat = DiscInfo->DiscStat.Flags;
1784 if((DiscInfo->DiscStat.Flags & DiscInfo_Disk_Mask) == DiscInfo_Disk_Empty) {
1785 UDFPrint(("Blank\n"));
1786 Vcb->BlankCD = TRUE;
1787 }
1788 if( (DiscInfo->DiscStat.Flags & DiscInfo_Disk_Mask) == DiscInfo_Disk_Empty ||
1789 (DiscInfo->DiscStat.Flags & DiscInfo_Ses_Mask) == DiscInfo_Ses_Incomplete) {
1790 // we shall mount empty disk to make it possible for
1791 // external applications to perform format operation
1792 // or something like this
1793 UDFPrint(("Try RAW_MOUNT\n"));
1794 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
1795 PacketTrack = TRUE;
1796 }
1797
1798#ifndef _BROWSE_UDF_
1799 // If drive returned reasonable value from ReadCapacity, do not use
1800 // last LeadIn/LeadOut
1801 if(Vcb->MediaClassEx != CdMediaClass_DVDpRW &&
1802 !ReadCapacityOk) {
1803 // +RW returns bad value
1804 UDFPrint(("+RW returns bad value\n"));
1805 Vcb->LastPossibleLBA = (DiscInfo->LastSesLeadOutLBA & 0x80000000) ?
1806 0 : DiscInfo->LastSesLeadOutLBA;
1807 if(!(DiscInfo->LastSesLeadInLBA & 0x80000000)) {
1808 Vcb->LastPossibleLBA = max(DiscInfo->LastSesLeadInLBA, Vcb->LastPossibleLBA);
1809 }
1810 }
1811#endif // _BROWSE_UDF_
1812 if((DiscInfo->Flags.Flags & DiscInfo_BGF_Mask) != 0) {
1813 UDFPrint(("ForceFP + MRW\n"));
1814 ForceFP = TRUE;
1815 Vcb->MRWStatus = DiscInfo->Flags.Flags & DiscInfo_BGF_Mask;
1816 // update addressing mode
1817 if(!MRWRetry) {
1819 MRWRetry = TRUE;
1820 goto MRWRetry_label;
1821 }
1822 }
1823 UDFPrint(("MRW state %x\n", Vcb->MRWStatus));
1824 if(Vcb->MediaClassEx == CdMediaClass_DVDRW) {
1825 if(Vcb->PhMediaCapFlags & CdCapFlags_RandomWritable) {
1826 UDFPrint(("DVD-RW Rewritable\n"));
1827 ForceFP = TRUE;
1828 } else
1829 if((DiscInfo->DiscStat.Flags & DiscInfo_Disk_Mask) == DiscInfo_Disk_Empty) {
1830 UDFPrint(("Blank DVD-RW\n"));
1831 ForceFP = TRUE;
1832 } else {
1833 UDFPrint(("DVD-RW Sequential\n"));
1834 NotFP = TRUE;
1835 }
1836 } else
1837 if(CdrwIsDvdOverwritable(Vcb->MediaClassEx)) {
1838 UDFPrint(("force Rewritable (2)\n"));
1839 ForceFP = TRUE;
1840 }
1841 // We have incomplete last session, so process each track from last to first
1842// Vcb->LastPossibleLBA = DiscInfo->LastSesLeadInLBA;
1843
1844 Vcb->LastSession = DiscInfo->Status.NumOfSes;
1845 Vcb->LastTrackNum = DiscInfo->Status.LastTrackNumLastSes;
1846 Vcb->FirstTrackNum = DiscInfo->FirstTrackNum;
1847 // some devices report LastTrackNum=0 for full disks
1848 Vcb->LastTrackNum = max(Vcb->LastTrackNum, Vcb->FirstTrackNum);
1849 if(!Vcb->LastTrackNum) {
1850 UDFPrint(("Try read 1st track...\n"));
1851 Vcb->LastTrackNum = 1;
1852 }
1853 UDFPrint(("DiskInfo: 1st trk %x, last trk %x\n", Vcb->FirstTrackNum, Vcb->LastTrackNum));
1854#ifdef UDF_FORMAT_MEDIA
1855 if(fms && fms->opt_disk_info) {
1856 UserPrint(("First track: %d\n"
1857 "Last track: %d\n", Vcb->FirstTrackNum, Vcb->LastTrackNum));
1858 UserPrint(("------------------------------------------\n"));
1859 }
1860#endif //UDF_FORMAT_MEDIA
1861
1862 RC = UDFReallocTrackMap(Vcb, Vcb->LastTrackNum+1);
1863 if(!OS_SUCCESS(RC))
1864 try_return(RC);
1865
1866 // Get last LBA from invisible track (if any)
1867 RtlZeroMemory(TrackInfoOut,sizeof(TRACK_INFO_BLOCK_USER_OUT));
1868
1869 TrackInfoIn->LBA_TrkNum = 0; // invisible track
1870 TrackInfoIn->Track = TRUE;
1871
1873 TrackInfoIn, sizeof(TRACK_INFO_BLOCK_USER_IN),
1874 TrackInfoOut,sizeof(TRACK_INFO_BLOCK_USER_OUT), TRUE, NULL);
1875 if(OS_SUCCESS(RC)) {
1876 if((Vcb->LastTrackNum < TrackInfoOut->TrackNum) &&
1877 TrackInfoOut->TrackLength &&
1878 (TrackInfoOut->TrackStartLBA != TrackInfoOut->NextWriteLBA)) {
1879 Vcb->LastTrackNum = TrackInfoOut->TrackNum;
1880 if(!(TrackInfoOut->NextWriteLBA & 0x80000000))
1881 Vcb->NWA = TrackInfoOut->NextWriteLBA;
1882 if(TrackInfoOut->TrackLength > 1) {
1883 Vcb->LastPossibleLBA =
1884 TrackInfoOut->TrackStartLBA + TrackInfoOut->TrackLength - (TrackInfoOut->TrackLength ? 1 : 0);
1885 UDFPrint((" set LastPossibleLBA=%x\n", Vcb->LastPossibleLBA));
1886 }
1887 }
1888
1889 UDFPrint(("Ses %d, Track %d (%x, len %x) PckSize %x: \n"
1890 " NWA: %x (%s) DatType:%x, %s %s %s %s TrkType:%x %s %s\n"
1891 " LRA: %x (%s) RC_LBA:%x\n",
1892 TrackInfoOut->SesNum,
1893 0,
1894 TrackInfoOut->TrackStartLBA,
1895 TrackInfoOut->TrackLength,
1896 TrackInfoOut->FixPacketSize,
1897
1898 TrackInfoOut->NextWriteLBA,
1899 TrackInfoOut->NWA_V & TrkInfo_NWA_V ? "vld" : "inv",
1900 TrackInfoOut->DataParam.Flags & TrkInfo_Dat_Mask,
1901 (TrackInfoOut->DataParam.Flags & TrkInfo_Packet) ? "Pck" : "",
1902 (TrackInfoOut->DataParam.Flags & TrkInfo_FP) ? "FP" : "",
1903 (TrackInfoOut->DataParam.Flags & TrkInfo_Blank) ? "Blank" : "",
1904 (TrackInfoOut->DataParam.Flags & TrkInfo_RT) ? "RT" : "",
1905
1906 TrackInfoOut->TrackParam.Flags & TrkInfo_Trk_Mask,
1907 (TrackInfoOut->TrackParam.Flags & TrkInfo_Copy) ? "Cpy" : "",
1908 (TrackInfoOut->TrackParam.Flags & TrkInfo_Damage) ? "Damage" : "",
1909
1910 TrackInfoOut->LastRecordedAddr,
1911 (TrackInfoOut->NWA_V & TrkInfo_LRA_V) ? "vld" : "inv",
1912
1913 TrackInfoOut->ReadCompatLBA
1914 ));
1915#ifdef UDF_FORMAT_MEDIA
1916 if(fms && fms->opt_disk_info) {
1917 UserPrint(("Invisible track: \n"));
1918 UserPrint((" Ses %d, Track %d (%x, len %x) PckSize %x: \n"
1919 " NWA: %x (%s) DatType:%x, %s %s %s %s TrkType:%x %s %s\n"
1920 " LRA: %x (%s) RC_LBA:%x\n",
1921 TrackInfoOut->SesNum,
1922 0,
1923 TrackInfoOut->TrackStartLBA,
1924 TrackInfoOut->TrackLength,
1925 TrackInfoOut->FixPacketSize,
1926
1927 TrackInfoOut->NextWriteLBA,
1928 TrackInfoOut->NWA_V & TrkInfo_NWA_V ? "vld" : "inv",
1929 TrackInfoOut->DataParam.Flags & TrkInfo_Dat_Mask,
1930 (TrackInfoOut->DataParam.Flags & TrkInfo_Packet) ? "Pck" : "",
1931 (TrackInfoOut->DataParam.Flags & TrkInfo_FP) ? "FP" : "",
1932 (TrackInfoOut->DataParam.Flags & TrkInfo_Blank) ? "Blank" : "",
1933 (TrackInfoOut->DataParam.Flags & TrkInfo_RT) ? "RT" : "",
1934
1935 TrackInfoOut->TrackParam.Flags & TrkInfo_Trk_Mask,
1936 (TrackInfoOut->TrackParam.Flags & TrkInfo_Copy) ? "Cpy" : "",
1937 (TrackInfoOut->TrackParam.Flags & TrkInfo_Damage) ? "Damage" : "",
1938
1939 TrackInfoOut->LastRecordedAddr,
1940 (TrackInfoOut->NWA_V & TrkInfo_LRA_V) ? "vld" : "inv",
1941
1942 TrackInfoOut->ReadCompatLBA
1943 ));
1944 }
1945#endif //UDF_FORMAT_MEDIA
1946
1947 }
1948
1949 for (TrackNumber=(LONG)DiscInfo->FirstTrackNum;TrackNumber <= (LONG)Vcb->LastTrackNum;TrackNumber++) {
1950
1951 RtlZeroMemory(TrackInfoOut,sizeof(TRACK_INFO_BLOCK_USER_OUT));
1952 TrackInfoIn->LBA_TrkNum = TrackNumber;
1953 TrackInfoIn->Track = TRUE;
1954
1956 TrackInfoIn, sizeof(TRACK_INFO_BLOCK_USER_IN),
1957 TrackInfoOut,sizeof(TRACK_INFO_BLOCK_USER_OUT), TRUE, NULL);
1958 // fill sector type map
1959 if(TrackInfoOut->TrackStartLBA & 0x80000000) {
1960 UDFPrint(("TrkInfo: Bad FirstLba (%x), change to %x\n", TrackInfoOut->TrackStartLBA, 0));
1961 Vcb->TrackMap[TrackNumber].FirstLba = 0;
1962 } else {
1963 Vcb->TrackMap[TrackNumber].FirstLba = TrackInfoOut->TrackStartLBA;
1964 }
1965 if(TrackInfoOut->TrackLength & 0x80000000) {
1966 UDFPrint(("TrkInfo: Bad TrackLength (%x), change to %x\n", TrackInfoOut->TrackLength,
1967 Vcb->LastPossibleLBA - Vcb->TrackMap[TrackNumber].FirstLba + 1));
1968 TrackInfoOut->TrackLength = Vcb->LastPossibleLBA - Vcb->TrackMap[TrackNumber].FirstLba + 1;
1969 }
1970 Vcb->TrackMap[TrackNumber].LastLba = TrackInfoOut->TrackStartLBA +
1971 TrackInfoOut->TrackLength -
1972 (TrackInfoOut->TrackLength ? 1 : 0);
1973
1974 Vcb->TrackMap[TrackNumber].TrackParam = TrackInfoOut->TrackParam.Flags;
1975 Vcb->TrackMap[TrackNumber].DataParam = TrackInfoOut->DataParam.Flags;
1976 Vcb->TrackMap[TrackNumber].NWA_V = TrackInfoOut->NWA_V;
1977 if((TrackInfoOut->NextWriteLBA & 0x80000000) ||
1978 (TrackInfoOut->NextWriteLBA < TrackInfoOut->TrackStartLBA)) {
1979 if(!(Vcb->TrackMap[TrackNumber].LastLba & 0x8000000)) {
1980 UDFPrint(("TrkInfo: set NWA to LastLba (%x)\n", Vcb->TrackMap[TrackNumber].LastLba));
1981 Vcb->TrackMap[TrackNumber].NWA =
1982 Vcb->TrackMap[TrackNumber].LastLba;
1983 } else {
1984 UDFPrint(("TrkInfo: set NWA to INV (1)\n"));
1985 Vcb->TrackMap[TrackNumber].NWA = 0;
1986 Vcb->TrackMap[TrackNumber].NWA_V = 0;
1987 }
1988 } else {
1989 if(!(TrackInfoOut->NextWriteLBA & 0x80000000)) {
1990 UDFPrint(("TrkInfo: Good NWA (%x)\n", TrackInfoOut->NextWriteLBA));
1991 Vcb->TrackMap[TrackNumber].NWA =
1992 TrackInfoOut->NextWriteLBA;
1993 } else {
1994 UDFPrint(("TrkInfo: set NWA to INV (2)\n"));
1995 Vcb->TrackMap[TrackNumber].NWA = 0;
1996 Vcb->TrackMap[TrackNumber].NWA_V = 0;
1997 }
1998 }
1999 Vcb->TrackMap[TrackNumber].Session = TrackInfoOut->SesNum;
2000 // for FP tracks we shall get PacketSize from returned info
2001 // otherwise set to default UDF value (0x20)
2002 if(NotFP) {
2003 UDFPrint(("Apply NotFP\n"));
2004 Vcb->TrackMap[TrackNumber].DataParam &= ~TrkInfo_FP;
2005#ifdef DBG
2006 TrackInfoOut->DataParam.Flags &= ~TrkInfo_FP;
2007#endif //DBG
2008 } else
2009 if(ForceFP) {
2010 UDFPrint(("Apply ForceFP\n"));
2011 PacketTrack = TRUE;
2012 Vcb->TrackMap[TrackNumber].DataParam |= TrkInfo_FP;
2013#ifdef DBG
2014 TrackInfoOut->DataParam.Flags |= TrkInfo_FP;
2015#endif //DBG
2016 }
2017 if(Vcb->TrackMap[TrackNumber].DataParam & TrkInfo_FP) {
2018 Vcb->TrackMap[TrackNumber].PacketSize = TrackInfoOut->FixPacketSize;
2019 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
2020 Vcb->FP_disc = TRUE;
2021 } else {
2022 Vcb->TrackMap[TrackNumber].PacketSize = PACKETSIZE_UDF;
2023 }
2024 // presence of Damaged track means, that we should mount this disk in RAW mode
2025 if(Vcb->TrackMap[TrackNumber].TrackParam & TrkInfo_Damage) {
2026 UDFPrint(("TrkInfo_Damage, Try RAW_MOUNT\n"));
2027 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
2028 }
2029 // presence of track with Unknown data type means, that we should mount
2030 // this disk in RAW mode
2031 if((TrackInfoOut->DataParam.Flags & TrkInfo_Dat_Mask) == TrkInfo_Trk_unknown) {
2032 UDFPrint(("Unknown DatType, Try RAW_MOUNT\n"));
2033 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
2034 }
2035
2036 PacketTrack |= ((TrackInfoOut->DataParam.Flags & TrkInfo_Packet) != 0);
2037
2038 UDFPrint(("Ses %d, Track %d (%x - %x) PckSize %x: \n"
2039 " NWA: %x (%s) DatType:%x, %s %s %s %s TrkType:%x %s %s\n"
2040 " LRA: %x (%s) RC_LBA:%x\n",
2041 TrackInfoOut->SesNum,
2042 TrackNumber,
2043 Vcb->TrackMap[TrackNumber].FirstLba,
2044 Vcb->TrackMap[TrackNumber].LastLba,
2045 TrackInfoOut->FixPacketSize,
2046
2047 TrackInfoOut->NextWriteLBA,
2048 TrackInfoOut->NWA_V & TrkInfo_NWA_V ? "vld" : "inv",
2049 TrackInfoOut->DataParam.Flags & TrkInfo_Dat_Mask,
2050 (TrackInfoOut->DataParam.Flags & TrkInfo_Packet) ? "Pck" : "",
2051 (TrackInfoOut->DataParam.Flags & TrkInfo_FP) ? "FP" : "",
2052 (TrackInfoOut->DataParam.Flags & TrkInfo_Blank) ? "Blank" : "",
2053 (TrackInfoOut->DataParam.Flags & TrkInfo_RT) ? "RT" : "",
2054
2055 TrackInfoOut->TrackParam.Flags & TrkInfo_Trk_Mask,
2056 (TrackInfoOut->TrackParam.Flags & TrkInfo_Copy) ? "Cpy" : "",
2057 (TrackInfoOut->TrackParam.Flags & TrkInfo_Damage) ? "Damage" : "",
2058
2059 TrackInfoOut->LastRecordedAddr,
2060 (TrackInfoOut->NWA_V & TrkInfo_LRA_V) ? "vld" : "inv",
2061
2062 TrackInfoOut->ReadCompatLBA
2063 ));
2064#ifdef UDF_FORMAT_MEDIA
2065 if(fms && fms->opt_disk_info) {
2066 UserPrint(("Track %d: \n", TrackNumber));
2067 UserPrint((" Ses %d, Track %d (%x, len %x) PckSize %x: \n"
2068 " NWA: %x (%s) DatType:%x, %s %s %s %s TrkType:%x %s %s\n"
2069 " LRA: %x (%s) RC_LBA:%x\n",
2070 TrackInfoOut->SesNum,
2071 TrackNumber,
2072 TrackInfoOut->TrackStartLBA,
2073 TrackInfoOut->TrackLength,
2074 TrackInfoOut->FixPacketSize,
2075
2076 TrackInfoOut->NextWriteLBA,
2077 TrackInfoOut->NWA_V & TrkInfo_NWA_V ? "vld" : "inv",
2078 TrackInfoOut->DataParam.Flags & TrkInfo_Dat_Mask,
2079 (TrackInfoOut->DataParam.Flags & TrkInfo_Packet) ? "Pck" : "",
2080 (TrackInfoOut->DataParam.Flags & TrkInfo_FP) ? "FP" : "",
2081 (TrackInfoOut->DataParam.Flags & TrkInfo_Blank) ? "Blank" : "",
2082 (TrackInfoOut->DataParam.Flags & TrkInfo_RT) ? "RT" : "",
2083
2084 TrackInfoOut->TrackParam.Flags & TrkInfo_Trk_Mask,
2085 (TrackInfoOut->TrackParam.Flags & TrkInfo_Copy) ? "Cpy" : "",
2086 (TrackInfoOut->TrackParam.Flags & TrkInfo_Damage) ? "Damage" : "",
2087
2088 TrackInfoOut->LastRecordedAddr,
2089 (TrackInfoOut->NWA_V & TrkInfo_LRA_V) ? "vld" : "inv",
2090
2091 TrackInfoOut->ReadCompatLBA
2092 ));
2093 }
2094#endif //UDF_FORMAT_MEDIA
2095
2096 if(TrackNumber == DiscInfo->FirstTrackNum) {
2097 if(!(Vcb->TrackMap[TrackNumber].FirstLba & 0x80000000)) {
2098 UDFPrint(("TrkInfo: Update FirstLBA (%x)\n", Vcb->TrackMap[TrackNumber].FirstLba));
2099 Vcb->FirstLBA = Vcb->TrackMap[TrackNumber].FirstLba;
2100 }
2101 }
2102 if((TrackInfoOut->SesNum == Vcb->LastSession) && !Vcb->FirstTrackNumLastSes) {
2103 if(!(Vcb->TrackMap[TrackNumber].FirstLba & 0x80000000)) {
2104 UDFPrint(("TrkInfo: Update FirstLBALastSes (%x)\n", Vcb->TrackMap[TrackNumber].FirstLba));
2105 Vcb->FirstLBALastSes = Vcb->TrackMap[TrackNumber].FirstLba;
2106 }
2107 Vcb->FirstTrackNumLastSes = TrackNumber;
2108 }
2109 }
2110
2111 if(!(TrackInfoOut->NextWriteLBA & 0x80000000) &&
2112 !(TrackInfoOut->TrackLength & 0x80000000) &&
2113 (Vcb->NWA < TrackInfoOut->NextWriteLBA)
2114 ) {
2115 UDFPrint((" set NWA to %x\n", TrackInfoOut->NextWriteLBA));
2116 if(Vcb->MediaClassEx != CdMediaClass_DVDpRW) {
2117 Vcb->NWA = TrackInfoOut->NextWriteLBA;
2118 } else {
2119 Vcb->NWA =
2120 TrackInfoOut->TrackStartLBA + TrackInfoOut->TrackLength - (TrackInfoOut->TrackLength ? 1 : 0);
2121 }
2122 }
2123 if(Vcb->MediaClassEx != CdMediaClass_DVDpRW &&
2124 !(TrackInfoOut->TrackLength & 0x80000000) &&
2125 TrackInfoOut->TrackLength > 1) {
2126 Vcb->LastPossibleLBA =
2127 TrackInfoOut->TrackStartLBA + TrackInfoOut->TrackLength - (TrackInfoOut->TrackLength ? 1 : 0);
2128 UDFPrint((" set LastPossibleLBA=%x\n", Vcb->LastPossibleLBA));
2129 }
2130 TrackNumber = Vcb->LastTrackNum;
2131 // quick formatted +RW returns bogus value
2132 if(Vcb->MediaClassEx == CdMediaClass_DVDpRW) {
2133 UDFPrint((" check quick formatted +RW\n"));
2134 if(Vcb->TrackMap[TrackNumber].LastLba &&
2135 !(Vcb->TrackMap[TrackNumber].LastLba & 0x80000000) &&
2136 Vcb->TrackMap[TrackNumber].LastLba < Vcb->LastPossibleLBA /*&&
2137 Vcb->TrackMap[TrackNumber].LastLba != Vcb->LastPossibleLBA*/
2138 ) {
2139 UDFPrint((" track LastLBA %x != LastPossibleLBA %x, verify\n",
2140 Vcb->TrackMap[TrackNumber].LastLba, Vcb->LastPossibleLBA));
2141
2142 if(Vcb->MRWStatus == DiscInfo_BGF_Complete) {
2143 UDFPrint((" complete MRW state\n"));
2144#ifdef _BROWSE_UDF_
2145 Vcb->LastPossibleLBA =
2146 Vcb->NWA =
2147 Vcb->LastLBA =
2148 Vcb->TrackMap[TrackNumber].LastLba;
2149 goto valid_track_length;
2150#endif // _BROWSE_UDF_
2151 } else
2152 if(Vcb->MRWStatus) {
2153 uint8* buff;
2155
2156 UDFPrint((" MRW state %x\n", Vcb->MRWStatus));
2157
2158 buff = (uint8*)DbgAllocatePoolWithTag(NonPagedPool, Vcb->WriteBlockSize, 'bNWD' );
2159 if(buff) {
2160 RC = UDFTRead(Vcb,
2161 buff,
2162 Vcb->WriteBlockSize,
2163 Vcb->TrackMap[TrackNumber].LastLba+1,
2164 &ReadBytes,
2167 if(!OS_SUCCESS(RC)) {
2168 UDFPrint((" Can't read beyond track LastLBA (%x)\n", Vcb->TrackMap[TrackNumber].LastLba+1));
2169 Vcb->LastLBA = Vcb->TrackMap[TrackNumber].LastLba;
2170 Vcb->NWA = Vcb->LastLBA+1;
2171 Vcb->TrackMap[TrackNumber].NWA_V = 1;
2172 Vcb->TrackMap[TrackNumber].NWA = Vcb->NWA;
2173 Vcb->TrackMap[TrackNumber].LastLba = Vcb->LastPossibleLBA;
2174 RC = STATUS_SUCCESS;
2175 goto valid_track_length;
2176 }
2177 }
2178 }
2179 }
2180 UDFPrint((" set track LastLBA %x\n", Vcb->LastPossibleLBA));
2181 Vcb->NWA =
2182 Vcb->LastLBA =
2183 Vcb->TrackMap[TrackNumber].LastLba =
2184 Vcb->LastPossibleLBA;
2185 }
2186valid_track_length:
2187 // Test for last empty session
2188 if((Vcb->TrackMap[TrackNumber].Session !=
2189 Vcb->TrackMap[TrackNumber-1].Session) &&
2190 (Vcb->LastSession > 1)) {
2191 // Note: some devices return negative track length
2192 if((Vcb->TrackMap[TrackNumber].LastLba <=
2193 Vcb->TrackMap[TrackNumber].FirstLba) ||
2194 (Vcb->TrackMap[TrackNumber].FirstLba ==
2195 Vcb->TrackMap[TrackNumber].NWA)) {
2196 // empty last session...
2197 Vcb->LastTrackNum--;
2198// TrackNumber--;
2199/* for(SesNum = Vcb->TrackMap[TrackNumber].Session;
2200 Vcb->TrackMap[TrackNumber].Session == SesNum;
2201 TrackNumber--) {
2202 }*/
2203 if(TrackNumber>1)
2204 Vcb->LastSession = Vcb->TrackMap[TrackNumber-1].Session;
2205 }
2206 }
2207
2208 TrackNumber = Vcb->LastTrackNum;
2209#ifdef _BROWSE_UDF_
2210 Vcb->LastLBA = min(Vcb->TrackMap[TrackNumber].LastLba, Vcb->TrackMap[TrackNumber].NWA);
2211#endif //_BROWSE_UDF_
2212
2213 if(Vcb->TrackMap[TrackNumber].NWA_V & TrkInfo_NWA_V) {
2214 UDFPrint((" NWA ok, set LastLBA to min(Last %x, NWA %x\n",
2215 Vcb->TrackMap[TrackNumber].LastLba,
2216 Vcb->TrackMap[TrackNumber].NWA));
2217 Vcb->LastLBA = min(Vcb->TrackMap[TrackNumber].LastLba, Vcb->TrackMap[TrackNumber].NWA);
2218 } else {
2219 UDFPrint((" no NWA, set LastLBA to Last %x\n", Vcb->TrackMap[TrackNumber].LastLba));
2220 Vcb->LastLBA = Vcb->TrackMap[TrackNumber].LastLba;
2221 }
2222
2223 Vcb->VCBFlags |= UDF_VCB_FLAGS_TRACKMAP;
2224 if(!PacketTrack && Vcb->MediaClassEx != CdMediaClass_DVDRAM ) {
2225 UDFPrint((" disable Raw mount\n"));
2226 Vcb->VCBFlags &= ~UDF_VCB_FLAGS_RAW_DISK;
2227 }
2228
2229try_exit: NOTHING;
2230
2231 } _SEH2_FINALLY {
2232 if(DiscInfo) MyFreePool__(DiscInfo);
2233 if(TrackInfoOut) MyFreePool__(TrackInfoOut);
2234 } _SEH2_END;
2235
2236 return RC;
2237} // end UDFReadDiscTrackInfo()
#define DiscInfo_Ses_Complete
Definition: cdrw_hw.h:2279
#define DiscInfo_Disk_OtherRW
Definition: cdrw_hw.h:2274
#define DiscInfo_Ses_Mask
Definition: cdrw_hw.h:2276
#define TrkInfo_RT
Definition: cdrw_hw.h:2420
#define DiscInfo_Disk_Complete
Definition: cdrw_hw.h:2273
#define DiscInfo_Ses_Empty
Definition: cdrw_hw.h:2277
#define TrkInfo_Trk_unknown
Definition: cdrw_hw.h:2393
#define TrkInfo_LRA_V
Definition: cdrw_hw.h:2430
#define TrkInfo_Trk_Mask
Definition: cdrw_hw.h:2385
#define DiscInfo_BGF_Complete
Definition: cdrw_hw.h:2302
#define DiscInfo_Disk_Empty
Definition: cdrw_hw.h:2271
#define DiscInfo_Disk_Erasable
Definition: cdrw_hw.h:2281
#define TrkInfo_NWA_V
Definition: cdrw_hw.h:2429
#define DiscInfo_BGF_Mask
Definition: cdrw_hw.h:2298
#define DiscInfo_Ses_Incomplete
Definition: cdrw_hw.h:2278
#define TrkInfo_Copy
Definition: cdrw_hw.h:2395
#define TrkInfo_Damage
Definition: cdrw_hw.h:2396
#define TrkInfo_Blank
Definition: cdrw_hw.h:2419
#define IOCTL_CDRW_READ_CAPACITY
Definition: cdrw_usr.h:128
#define DEFAULT_LAST_LBA_FP_CD
Definition: cdrw_usr.h:1820
struct _TRACK_INFO_BLOCK_USER_OUT * PTRACK_INFO_BLOCK_USER_OUT
struct _TRACK_INFO_BLOCK_USER_IN * PTRACK_INFO_BLOCK_USER_IN
struct _DISC_INFO_BLOCK_USER_OUT * PDISC_INFO_BLOCK_USER_OUT
#define IOCTL_CDRW_READ_TRACK_INFO
Definition: cdrw_usr.h:92
#define CdrwIsDvdOverwritable(MediaClassEx)
Definition: cdrw_usr.h:804
#define DEFAULT_LAST_LBA_BD
Definition: cdrw_usr.h:1822
#define CdMediaClass_DDCDR
Definition: cdrw_usr.h:753
#define CdMediaClass_DDCDRW
Definition: cdrw_usr.h:754
#define CdMediaClass_DDCDROM
Definition: cdrw_usr.h:752
#define IOCTL_CDRW_READ_DISC_INFO
Definition: cdrw_usr.h:93
static unsigned char buff[32768]
Definition: fatten.c:17
long LONG
Definition: pedump.c:60
OSSTATUS UDFTRead(IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T ReadBytes, IN uint32 Flags)
Definition: phys_lib.cpp:596
DISC_STATUS_INFO_USER_OUT Status
Definition: cdrw_usr.h:630
ULONG LogicalBlockAddress
Definition: cdrw_hw.h:1471
union _TRACK_INFO_BLOCK_USER_OUT::@922 TrackParam
union _TRACK_INFO_BLOCK_USER_OUT::@923 DataParam
#define UDF_VCB_FLAGS_TRACKMAP
Definition: udf_common.h:473

Referenced by UDFGetDiskInfo().

◆ UDFReadInSector()

OSSTATUS UDFReadInSector ( IN PVCB  Vcb,
IN BOOLEAN  Translate,
IN ULONG  Lba,
IN ULONG  i,
IN ULONG  l,
IN BOOLEAN  Direct,
OUT PCHAR  Buffer,
OUT PSIZE_T  ReadBytes 
)

◆ UDFResetDeviceDriver()

OSSTATUS UDFResetDeviceDriver ( IN PVCB  Vcb,
IN PDEVICE_OBJECT  TargetDeviceObject,
IN BOOLEAN  Unlock 
)

Definition at line 4199 of file phys_lib.cpp.

4204{
4207 OSSTATUS RC;
4208 if(!tmp)
4211 tmp->UnlockTray = (Unlock ? 1 : 0);
4212 tmp->MagicWord = 0x3a6 | (Unlock ? 1 : 0);
4214 tmp, sizeof(CDRW_RESET_DRIVER_USER_IN), NULL, 0, TRUE,NULL);
4215 if(Vcb) {
4216 Vcb->LastReadTrack = 0;
4217 Vcb->LastModifiedTrack = 0;
4218 Vcb->OPCDone = FALSE;
4219 if((Vcb->VCBFlags & UDF_VCB_FLAGS_USE_CAV) &&
4220 Vcb->TargetDeviceObject) {
4221 // limit both read & write speed to last write speed for CAV mode
4222 // some drives damage data when speed is adjusted during recording process
4223 // even in packet mode
4225 }
4227 }
4228
4229 MyFreePool__(tmp);
4230 return RC;
4231} // end UDFResetDeviceDriver()
#define IOCTL_CDRW_RESET_DRIVER_EX
Definition: cdrw_usr.h:122
struct _CDRW_RESET_DRIVER_USER_IN * PCDRW_RESET_DRIVER_USER_IN
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1675
@ Unlock
Definition: ntsecapi.h:294

Referenced by UDFCommonCleanup(), UDFDoDismountSequence(), UDFGetDiskInfo(), UDFMountVolume(), and UDFRecoverFromError().

◆ UDFStopEjectWaiter()

VOID UDFStopEjectWaiter ( PVCB  Vcb)

Definition at line 673 of file phys_eject.cpp.

673 {
674
675 UDFPrint((" UDFStopEjectWaiter: try\n"));
676 UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE);
677 _SEH2_TRY {
678 if(Vcb->EjectWaiter) {
679 UDFPrint((" UDFStopEjectWaiter: set flag\n"));
680 KeSetEvent( &(Vcb->EjectWaiter->StopReq), 0, FALSE );
681 } else {
682// return;
683 }
685 BrutePoint();
686 } _SEH2_END;
687 UDFReleaseResource(&(Vcb->VCBResource));
688
689 _SEH2_TRY {
690 if(Vcb->VCBFlags & UDF_VCB_FLAGS_STOP_WAITER_EVENT) {
691 UDFPrint((" UDFStopEjectWaiter: wait\n"));
693 }
694 Vcb->VCBFlags &= ~UDF_VCB_FLAGS_STOP_WAITER_EVENT;
696 BrutePoint();
697 } _SEH2_END;
698 ASSERT(!Vcb->EjectWaiter);
699 UDFPrint((" UDFStopEjectWaiter: exit\n"));
700
701} // end UDFStopEjectWaiter()
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define UDF_VCB_FLAGS_STOP_WAITER_EVENT
Definition: udf_common.h:479
@ Executive
Definition: ketypes.h:415

Referenced by UDFCheckForDismount(), UDFCommonDeviceControl(), UDFCommonShutdown(), UDFDismountVcb(), UDFDismountVolume(), UDFInvalidateVolumes(), UDFPnpQueryRemove(), UDFPnpRemove(), UDFPnpSurpriseRemove(), and UDFVerifyVolume().

◆ UDFSyncCache()

NTSTATUS UDFSyncCache ( IN PVCB  Vcb)

Definition at line 52 of file phys_lib.cpp.

55{
56 UDFPrint(("UDFSyncCache:\n"));
57 OSSTATUS RC;
58 RC = UDFPhSendIOCTL( IOCTL_CDRW_SYNC_CACHE, Vcb->TargetDeviceObject,
59 NULL,0, NULL,0, FALSE, NULL);
60 if(OS_SUCCESS(RC)) {
61 // clear LAST_WRITE flag
62 Vcb->VCBFlags &= ~UDF_VCB_LAST_WRITE;
63 }
64 return RC;
65} // end UDFSyncCache()
#define IOCTL_CDRW_SYNC_CACHE
Definition: cdrw_usr.h:81

Referenced by UDFPrepareForReadOperation(), UDFRecoverFromError(), and UDFUpdateNWA().

◆ UDFTIOVerify()

OSSTATUS __fastcall UDFTIOVerify ( IN void _Vcb,
IN void Buffer,
IN SIZE_T  Length,
IN uint32  LBA,
OUT PSIZE_T  IOBytes,
IN uint32  Flags 
)

Referenced by UDFVWorkItem().

◆ UDFTRead()

OSSTATUS UDFTRead ( PVOID  _Vcb,
PVOID  Buffer,
SIZE_T  Length,
ULONG  LBA,
PSIZE_T  ReadBytes,
ULONG  Flags = 0 
)

◆ UDFTReadVerify()

OSSTATUS UDFTReadVerify ( IN void _Vcb,
IN void Buffer,
IN SIZE_T  Length,
IN uint32  LBA,
OUT PSIZE_T  ReadBytes,
IN uint32  Flags 
)

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFTWrite()

OSSTATUS UDFTWrite ( IN PVOID  _Vcb,
IN PVOID  Buffer,
IN SIZE_T  Length,
IN ULONG  LBA,
OUT PSIZE_T  WrittenBytes,
IN ULONG  Flags = 0 
)

◆ UDFTWriteVerify()

OSSTATUS UDFTWriteVerify ( IN void _Vcb,
IN void Buffer,
IN SIZE_T  Length,
IN uint32  LBA,
OUT PSIZE_T  WrittenBytes,
IN uint32  Flags 
)

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFUpdateNWA()

VOID UDFUpdateNWA ( PVCB  Vcb,
ULONG  LBA,
ULONG  BCount,
OSSTATUS  RC 
)

Definition at line 3826 of file phys_lib.cpp.

3832{
3833#ifndef UDF_READ_ONLY_BUILD
3834#ifdef _BROWSE_UDF_
3835 if(!OS_SUCCESS(RC)) {
3836 return;
3837 }
3838 if(!Vcb->CDR_Mode) {
3839
3840 if((Vcb->MediaClassEx == CdMediaClass_DVDRW ||
3841 Vcb->MediaClassEx == CdMediaClass_DVDpRW ||
3842 Vcb->MediaClassEx == CdMediaClass_DVDRAM ||
3843 Vcb->MRWStatus == DiscInfo_BGF_Interrupted ||
3844 Vcb->MRWStatus == DiscInfo_BGF_InProgress)
3845 && (LBA+BCount-1) > Vcb->LastLBA) {
3846 ASSERT(Vcb->NWA > Vcb->LastLBA);
3847 Vcb->NWA = LBA+BCount;
3848 Vcb->LastLBA = Vcb->NWA-1;
3849 }
3850 if(Vcb->VCBFlags & UDF_VCB_FLAGS_FORCE_SYNC_CACHE)
3851 goto sync_cache;
3852/* if(Vcb->CdrwBufferSize) {
3853 Vcb->CdrwBufferSizeCounter += BCount * 2048;
3854 if(Vcb->CdrwBufferSizeCounter >= Vcb->CdrwBufferSize + 2*2048) {
3855 UDFPrint((" UDFUpdateNWA: buffer is full, sync...\n"));
3856 Vcb->CdrwBufferSizeCounter = 0;
3857 goto sync_cache;
3858 }
3859 }*/
3860 if(Vcb->SyncCacheState == SYNC_CACHE_RECOVERY_RETRY) {
3862 }
3863 Vcb->SyncCacheState = SYNC_CACHE_RECOVERY_NONE;
3864 return;
3865 }
3866 if(Vcb->LastLBA < (LBA+BCount))
3867 Vcb->LastLBA = LBA+BCount;
3868 if(Vcb->NWA)
3869 Vcb->NWA+=BCount+7;
3870sync_cache:
3871 if(!(Vcb->CompatFlags & UDF_VCB_IC_NO_SYNCCACHE_AFTER_WRITE)) {
3872 UDFPrint((" UDFUpdateNWA: syncing...\n"));
3873 RC = UDFSyncCache(Vcb);
3874 }
3875#endif //_BROWSE_UDF_
3876#endif //UDF_READ_ONLY_BUILD
3877} // end UDFUpdateNWA()

Referenced by UDFPrepareForWriteOperation(), and UDFTWrite().

◆ UDFUseStandard()

OSSTATUS UDFUseStandard ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb 
)

Definition at line 2386 of file phys_lib.cpp.

2390{
2394 uint32 LocalTrackCount;
2395// uint32 LocalTocLength;
2396 uint32 TocEntry;
2397#ifdef _BROWSE_UDF_
2398 uint32 OldTrkNum;
2399 uint32 TrkNum;
2401#endif //_BROWSE_UDF_
2402#ifdef UDF_FORMAT_MEDIA
2403 PUDFFmtState fms = Vcb->fms;
2404#else
2405 #define fms FALSE
2406#endif //UDF_FORMAT_MEDIA
2407
2408 UDFPrint(("UDFUseStandard\n"));
2409
2410 _SEH2_TRY {
2411
2412 if(!toc || !LastSes) {
2414 }
2415 RtlZeroMemory(toc,sizeof(READ_TOC_TOC));
2416
2417 Vcb->VCBFlags |= UDF_VCB_FLAGS_USE_STD;
2418
2420 toc,sizeof(READ_TOC_USER_OUT),
2421 toc,sizeof(READ_TOC_USER_OUT),
2422 TRUE,NULL );
2423
2424 if((RC == STATUS_DEVICE_NOT_READY) || (RC == STATUS_NO_MEDIA_IN_DEVICE)) {
2425 try_return(RC);
2426 }
2427#ifdef UDF_FORMAT_MEDIA
2428 if(fms->opt_media == MT_none) {
2430 }
2431#endif //UDF_FORMAT_MEDIA
2432
2433 // If even standard read toc does not work, then use default values
2434 if(!OS_SUCCESS(RC)) {
2435
2436 RC = UDFReallocTrackMap(Vcb, 2);
2437 if(!OS_SUCCESS(RC)) {
2438 try_return(RC);
2439 }
2440
2441 Vcb->LastSession=1;
2442 Vcb->FirstTrackNum=1;
2443// Vcb->FirstLBA=0;
2444 Vcb->LastTrackNum=1;
2445 Vcb->TrackMap[1].FirstLba = Vcb->FirstLBA;
2446 Vcb->TrackMap[1].LastLba = Vcb->LastLBA;
2447 Vcb->TrackMap[1].PacketSize = PACKETSIZE_UDF;
2448#ifdef UDF_FORMAT_MEDIA
2449 if(!fms) {
2450#endif //UDF_FORMAT_MEDIA
2451
2452#ifdef _BROWSE_UDF_
2453#ifdef UDF_HDD_SUPPORT
2456 }
2457#endif //UDF_HDD_SUPPORT
2458#endif //_BROWSE_UDF_
2459
2460#ifdef UDF_FORMAT_MEDIA
2461 } else {
2462
2463 if(fms->opt_media == MT_HD) {
2464 Vcb->LastPossibleLBA = Vcb->LastLBA;
2466 }
2467 }
2468#endif //UDF_FORMAT_MEDIA
2469 Vcb->LastPossibleLBA = max(Vcb->LastLBA, DEFAULT_LAST_LBA_FP_CD);
2470 Vcb->TrackMap[1].DataParam = TrkInfo_Dat_XA | TrkInfo_FP | TrkInfo_Packet;
2471 Vcb->TrackMap[1].TrackParam = TrkInfo_Trk_XA;
2472 Vcb->TrackMap[1].NWA = 0xffffffff;
2473 Vcb->NWA = DEFAULT_LAST_LBA_FP_CD + 7 + 1;
2475 }
2476
2477#ifdef _CONSOLE
2478 Vcb->PhDeviceType = FILE_DEVICE_CD_ROM;
2479#endif //_CONSOLE
2480
2481 LocalTrackCount = toc->Tracks.Last_TrackSes - toc->Tracks.First_TrackSes + 1;
2482// LocalTocLength = PtrOffset( toc, &(toc->TrackData[LocalTrackCount + 1]) ); /* FIXME ReactOS Assume PtrOffset is not changing it's arguments? */
2483
2484 // Get out if there is an immediate problem with the TOC.
2485 if(toc->Tracks.First_TrackSes > toc->Tracks.Last_TrackSes) {
2487 }
2488
2489#ifdef _BROWSE_UDF_
2490 Vcb->LastTrackNum=toc->Tracks.Last_TrackSes;
2491 Vcb->FirstTrackNum=toc->Tracks.First_TrackSes;
2492 // some devices report LastTrackNum=0 for full disks
2493 Vcb->LastTrackNum = max(Vcb->LastTrackNum, Vcb->FirstTrackNum);
2494
2496/* if(Vcb->TrackMap) {
2497 MyFreePool__(Vcb->TrackMap);
2498 Vcb->TrackMap = NULL;
2499 }
2500 Vcb->TrackMap = (PUDFTrackMap)
2501 MyAllocatePool__(NonPagedPool, (MAXIMUM_NUMBER_OF_TRACKS+1)*sizeof(UDFTrackMap));
2502 if(!Vcb->TrackMap) {
2503 MyFreePool__(toc);
2504 return STATUS_INSUFFICIENT_RESOURCES;
2505 }
2506 RtlZeroMemory(Vcb->TrackMap,(MAXIMUM_NUMBER_OF_TRACKS+1)*sizeof(UDFTrackMap));
2507*/
2508 if(!OS_SUCCESS(RC)) {
2509 BrutePoint();
2510 try_return(RC);
2511 }
2512 // find 1st and last session
2514 LastSes,sizeof(GET_LAST_SESSION_USER_OUT),
2515 LastSes,sizeof(GET_LAST_SESSION_USER_OUT),
2516 TRUE,NULL );
2517
2518 if(OS_SUCCESS(RC)) {
2519 TrkNum = LastSes->LastSes_1stTrack.TrackNum;
2520 Vcb->LastSession = LastSes->Sessions.First_TrackSes;
2521 for(TocEntry=0;TocEntry<LocalTrackCount + 1;TocEntry++) {
2522 if(toc->TrackData[TocEntry].TrackNum == TrkNum) {
2523 Vcb->TrackMap[TrkNum].Session = Vcb->LastSession;
2524 }
2525 }
2526 }
2527
2528 OldTrkNum = 0;
2529 // Scan toc for first & last LBA
2530 for(TocEntry=0;TocEntry<LocalTrackCount + 1;TocEntry++) {
2531#define TempMSF toc->TrackData[TocEntry].LBA
2532 TrkNum = toc->TrackData[TocEntry].TrackNum;
2533#ifdef UDF_DBG
2534 if (TrkNum >= MAXIMUM_NUMBER_OF_TRACKS &&
2535 TrkNum != TOC_LastTrack_ID) {
2536 UDFPrint(("UDFUseStandard: Array out of bounds\n"));
2537 BrutePoint();
2539 }
2540 UDFPrint(("Track N %d (0x%x) first LBA %ld (%lx) \n",TrkNum,TrkNum,
2542 MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3])));
2543#endif // UDF_DBG
2544 if(Vcb->FirstTrackNum == TrkNum) {
2545 Vcb->FirstLBA = MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3]);
2546 if(Vcb->FirstLBA & 0x80000000) {
2547 Vcb->FirstLBA = 0;
2548 }
2549 }
2550 if(TOC_LastTrack_ID == TrkNum) {
2551 Vcb->LastLBA = MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3])-1;
2552 Vcb->TrackMap[OldTrkNum].LastLba = Vcb->LastLBA-1;
2553 UDFPrint(("UDFUseStandard: Last track entry, break TOC scan\n"));
2554// continue;
2555 break;
2556 } else {
2557 Vcb->TrackMap[TrkNum].FirstLba = MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3]);
2558 if(Vcb->TrackMap[TrkNum].FirstLba & 0x80000000)
2559 Vcb->TrackMap[TrkNum].FirstLba = 0;
2560 if(TrkNum) {
2561 if (TOC_LastTrack_ID == OldTrkNum) {
2562 UDFPrint(("UDFUseStandard: Wrong previous track number\n"));
2563 BrutePoint();
2564 } else {
2565 Vcb->TrackMap[OldTrkNum].LastLba = Vcb->TrackMap[TrkNum].FirstLba-1;
2566 }
2567 }
2568 }
2569 // check track type
2570 switch(toc->TrackData[TocEntry].Control & TocControl_TrkMode_Mask) {
2573 Vcb->TrackMap[TrkNum].DataParam = TrkInfo_Dat_XA;
2574 Vcb->TrackMap[TrkNum].TrackParam = TrkInfo_Trk_XA;
2575 break;
2576 default:
2577 Vcb->TrackMap[TrkNum].DataParam = TrkInfo_Dat_unknown;
2578 Vcb->TrackMap[TrkNum].TrackParam = TrkInfo_Trk_unknown;
2579 }
2580 OldTrkNum = TrkNum;
2581#undef TempMSF
2582 }
2583
2584 TrkNum = Vcb->LastTrackNum;
2585 RC = STATUS_SUCCESS;
2586 // find last _valid_ track
2587 for(;TrkNum;TrkNum--) {
2588 if((Vcb->TrackMap[TrkNum].DataParam != TrkInfo_Dat_unknown) &&
2589 (Vcb->TrackMap[TrkNum].TrackParam != TrkInfo_Trk_unknown)) {
2591 Vcb->LastTrackNum = TrkNum;
2592 break;
2593 }
2594 }
2595 // no valid tracks...
2596 if(!TrkNum) {
2597 UDFPrint(("UDFUseStandard: no valid tracks...\n"));
2599 }
2600 i = 0;
2601
2602 // Check for last VP track. Some last sectors may belong to Link-data &
2603 // be unreadable. We should forget about them, because UDF needs
2604 // last _readable_ sector.
2605 while(!OS_SUCCESS(RC) && (i<8)) {
2606 RC = UDFPhReadSynchronous(Vcb->TargetDeviceObject, (int8*)toc, Vcb->BlockSize,
2607 ((uint64)(Vcb->TrackMap[TrkNum].LastLba-i)) << Vcb->BlockSizeBits, &ReadBytes, PH_TMP_BUFFER);
2608 i++;
2609 }
2610 if(OS_SUCCESS(RC)) {
2611 Vcb->LastLBA = Vcb->TrackMap[TrkNum].LastLba-i+1;
2612/* if(i) {
2613 Vcb->TrackMap[TrkNum].PacketSize = PACKETSIZE_UDF;
2614 Vcb->TrackMap[TrkNum].;
2615 }*/
2616 } else {
2617
2618 // Check for FP track. READ_TOC reports actual track length, but
2619 // Link-data is hidden & unreadable for us. So, available track
2620 // length may be less than actual. Here we assume that Packet-size
2621 // is PACKETSIZE_UDF.
2622 i = 0;
2623 len = Vcb->TrackMap[TrkNum].LastLba - Vcb->TrackMap[TrkNum].FirstLba + 1;
2625
2626 while(!OS_SUCCESS(RC) && (i<9)) {
2627 RC = UDFPhReadSynchronous(Vcb->TargetDeviceObject, (int8*)toc, Vcb->BlockSize,
2628 ((uint64)(Vcb->TrackMap[TrkNum].FirstLba-i+len)) << Vcb->BlockSizeBits, &ReadBytes, PH_TMP_BUFFER);
2629 i++;
2630 }
2631 if(OS_SUCCESS(RC)) {
2632 Vcb->LastLBA =
2633 Vcb->TrackMap[TrkNum].LastLba = Vcb->TrackMap[TrkNum].FirstLba-i+len+1;
2634 Vcb->TrackMap[TrkNum].PacketSize = PACKETSIZE_UDF;
2635// Vcb->TrackMap[TrkNum].;
2636 } else
2638 // wrap return code from Audio-disk
2639 RC = STATUS_SUCCESS;
2640 }
2641 }
2642
2643#ifdef UDF_CDRW_EMULATION_ON_ROM
2644 Vcb->LastPossibleLBA = Vcb->LastLBA+7+1+1024;
2645 Vcb->NWA = Vcb->LastLBA+7+1;
2646#else
2647 Vcb->LastPossibleLBA =
2648 Vcb->NWA = Vcb->LastLBA+7+1;
2649#endif //UDF_CDRW_EMULATION_ON_ROM
2650
2651#else //_BROWSE_UDF_
2652
2653 Vcb->FirstTrackNum=toc->Tracks.Last_TrackSes;
2654 Vcb->LastTrackNum=toc->Tracks.First_TrackSes;
2655
2656 // Scan toc for first & last LBA
2657 for(TocEntry=0;TocEntry<LocalTrackCount + 1;TocEntry++) {
2658#define TempMSF toc->TrackData[TocEntry].LBA
2659 if(Vcb->FirstTrackNum == toc->TrackData[TocEntry].TrackNum) {
2660 Vcb->FirstLBA = MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3]);
2661 if(Vcb->FirstLBA & 0x80000000) {
2662 Vcb->FirstLBA = 0;
2663 }
2664 }
2665 if(TOC_LastTrack_ID == toc->TrackData[TocEntry].TrackNum) {
2666 Vcb->LastLBA = MSF_TO_LBA(TempMSF[1],TempMSF[2],TempMSF[3])-1;
2667 }
2668#undef TempMSF
2669 }
2670
2671// Vcb->LastLBA=PacketVariable2Fixed(Vcb->LastLBA)-2;
2672 Vcb->LastPossibleLBA = DEFAULT_LAST_LBA_FP_CD;
2673#endif //_BROWSE_UDF_
2674try_exit: NOTHING;
2675 } _SEH2_FINALLY {
2676 if(toc) MyFreePool__(toc);
2677 if(LastSes) MyFreePool__(LastSes);
2678 } _SEH2_END;
2679
2680 return RC;
2681} // end UDFUseStandard()
#define TocControl_TrkMode_IncrData
Definition: cdrw_hw.h:1512
#define TocControl_TrkMode_Mask
Definition: cdrw_hw.h:1508
#define TrkInfo_Dat_unknown
Definition: cdrw_hw.h:2415
#define TrkInfo_Trk_XA
Definition: cdrw_hw.h:2389
#define MAXIMUM_NUMBER_OF_TRACKS
Definition: cdrw_hw.h:834
#define TOC_LastTrack_ID
Definition: cdrw_hw.h:1531
#define TocControl_TrkMode_Data
Definition: cdrw_hw.h:1511
PREAD_TOC_TOC PREAD_TOC_USER_OUT
Definition: cdrw_usr.h:1379
PREAD_TOC_SES PGET_LAST_SESSION_USER_OUT
Definition: cdrw_usr.h:1382
long long int64
Definition: platform.h:13
#define UDFGetDevType(DevObj)
Definition: env_spec.h:148
GLenum GLsizei len
Definition: glext.h:6722
#define IOCTL_CDROM_GET_LAST_SESSION
Definition: ntddcdrm.h:64
#define IOCTL_CDROM_READ_TOC
Definition: ntddcdrm.h:34
#define FILE_DEVICE_DISK
Definition: winioctl.h:52
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:70
UCHAR First_TrackSes
Definition: cdrw_hw.h:1527
TOC_TRACK_INFO LastSes_1stTrack
Definition: cdrw_hw.h:1542
READ_TOC_HEADER Sessions
Definition: cdrw_hw.h:1541
TOC_TRACK_INFO TrackData[MAXIMUM_NUMBER_OF_TRACKS+1]
Definition: cdrw_hw.h:1535
READ_TOC_HEADER Tracks
Definition: cdrw_hw.h:1534
UCHAR TrackNum
Definition: cdrw_hw.h:1520
#define UDF_VCB_FLAGS_USE_STD
Definition: udf_common.h:477
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141

Referenced by UDFGetDiskInfo().

◆ UDFWriteData()

OSSTATUS UDFWriteData ( IN PVCB  Vcb,
IN BOOLEAN  Translate,
IN LONGLONG  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Direct,
IN PCHAR  Buffer,
OUT PSIZE_T  WrittenBytes 
)

◆ UDFWriteInSector()

OSSTATUS UDFWriteInSector ( IN PVCB  Vcb,
IN BOOLEAN  Translate,
IN ULONG  Lba,
IN ULONG  i,
IN ULONG  l,
IN BOOLEAN  Direct,
OUT PCHAR  Buffer,
OUT PSIZE_T  WrittenBytes 
)

◆ UDFWriteSectors()

OSSTATUS UDFWriteSectors ( IN PVCB  Vcb,
IN BOOLEAN  Translate,
IN ULONG  Lba,
IN ULONG  WBCount,
IN BOOLEAN  Direct,
IN PCHAR  Buffer,
OUT PSIZE_T  WrittenBytes 
)

Variable Documentation

◆ LockMode

◆ open_as_device

BOOLEAN open_as_device
extern

Definition at line 14 of file env_spec_w32.cpp.

Referenced by my_open().

◆ opt_invalidate_volume

BOOLEAN opt_invalidate_volume
extern

Definition at line 9 of file env_spec_w32.cpp.

Referenced by my_open().