Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

share.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1985 - 1999, Microsoft Corporation 00004 00005 Module Name: 00006 00007 share.c 00008 00009 Abstract: 00010 00011 Implements sharing for input and output handles 00012 00013 Author: 00014 00015 Therese Stowell (thereses) 11-Nov-1990 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #include "precomp.h" 00022 #pragma hdrstop 00023 00024 NTSTATUS 00025 ConsoleAddShare( 00026 IN ACCESS_MASK DesiredAccess, 00027 IN ULONG DesiredShareAccess, 00028 IN OUT PCONSOLE_SHARE_ACCESS ShareAccess, 00029 IN OUT PHANDLE_DATA HandleData 00030 ) 00031 00032 { 00033 ULONG Ocount; 00034 ULONG ReadAccess; 00035 ULONG WriteAccess; 00036 ULONG SharedRead; 00037 ULONG SharedWrite; 00038 00039 // 00040 // Set the access type in the file object for the current accessor. 00041 // 00042 00043 ReadAccess = (DesiredAccess & GENERIC_READ) != 0; 00044 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0; 00045 00046 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0; 00047 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0; 00048 00049 // 00050 // Now check to see whether or not the desired accesses are compatible 00051 // with the way that the file is currently open. 00052 // 00053 00054 Ocount = ShareAccess->OpenCount; 00055 00056 if ( (ReadAccess && (ShareAccess->SharedRead < Ocount)) 00057 || 00058 (WriteAccess && (ShareAccess->SharedWrite < Ocount)) 00059 || 00060 ((ShareAccess->Readers != 0) && !SharedRead) 00061 || 00062 ((ShareAccess->Writers != 0) && !SharedWrite) 00063 ) { 00064 00065 // 00066 // The check failed. Simply return to the caller indicating that the 00067 // current open cannot access the file. 00068 // 00069 00070 return STATUS_SHARING_VIOLATION; 00071 00072 } else { 00073 00074 // 00075 // The check was successful. Update the counter information in the 00076 // shared access structure for this open request if the caller 00077 // specified that it should be updated. 00078 // 00079 00080 ShareAccess->OpenCount++; 00081 00082 ShareAccess->Readers += ReadAccess; 00083 ShareAccess->Writers += WriteAccess; 00084 00085 ShareAccess->SharedRead += SharedRead; 00086 ShareAccess->SharedWrite += SharedWrite; 00087 HandleData->Access = DesiredAccess; 00088 HandleData->ShareAccess = DesiredShareAccess; 00089 00090 return STATUS_SUCCESS; 00091 } 00092 } 00093 00094 NTSTATUS 00095 ConsoleDupShare( 00096 IN ACCESS_MASK DesiredAccess, 00097 IN ULONG DesiredShareAccess, 00098 IN OUT PCONSOLE_SHARE_ACCESS ShareAccess, 00099 IN OUT PHANDLE_DATA TargetHandleData 00100 ) 00101 00102 { 00103 ULONG ReadAccess; 00104 ULONG WriteAccess; 00105 ULONG SharedRead; 00106 ULONG SharedWrite; 00107 00108 // 00109 // Set the access type in the file object for the current accessor. 00110 // 00111 00112 ReadAccess = (DesiredAccess & GENERIC_READ) != 0; 00113 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0; 00114 00115 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0; 00116 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0; 00117 00118 if (ShareAccess->OpenCount == 0) { 00119 ASSERT (FALSE); 00120 return STATUS_SHARING_VIOLATION; 00121 } 00122 00123 ShareAccess->OpenCount++; 00124 00125 ShareAccess->Readers += ReadAccess; 00126 ShareAccess->Writers += WriteAccess; 00127 00128 ShareAccess->SharedRead += SharedRead; 00129 ShareAccess->SharedWrite += SharedWrite; 00130 00131 TargetHandleData->Access = DesiredAccess; 00132 TargetHandleData->ShareAccess = DesiredShareAccess; 00133 00134 return STATUS_SUCCESS; 00135 } 00136 00137 NTSTATUS 00138 ConsoleRemoveShare( 00139 IN ULONG DesiredAccess, 00140 IN ULONG DesiredShareAccess, 00141 IN OUT PCONSOLE_SHARE_ACCESS ShareAccess 00142 ) 00143 00144 { 00145 ULONG ReadAccess; 00146 ULONG WriteAccess; 00147 ULONG SharedRead; 00148 ULONG SharedWrite; 00149 00150 // 00151 // Set the access type in the file object for the current accessor. 00152 // 00153 00154 ReadAccess = (DesiredAccess & GENERIC_READ) != 0; 00155 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0; 00156 00157 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0; 00158 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0; 00159 00160 if (ShareAccess->OpenCount == 0) { 00161 ASSERT (FALSE); 00162 return STATUS_UNSUCCESSFUL; 00163 } 00164 00165 ShareAccess->OpenCount--; 00166 00167 ShareAccess->Readers -= ReadAccess; 00168 ShareAccess->Writers -= WriteAccess; 00169 00170 ShareAccess->SharedRead -= SharedRead; 00171 ShareAccess->SharedWrite -= SharedWrite; 00172 00173 return STATUS_SUCCESS; 00174 }

Generated on Sat May 15 19:41:49 2004 for test by doxygen 1.3.7