static int gsc_close(dev_t dev) { gsc_softc_t *sp; int unit = minor(dev); Trace1(2, "gsc_close: close unit %d", unit); if (unit < 0 || unit >= MAX_UNITS) { return (ENODEV); } sp = &softinfo[unit]; if (sp->iscfg == 0) { return (ENODEV); } simple_lock(&sp->dd_lock); sp->isopen = 0; simple_unlock(&sp->dd_lock); return (0); }
static int gsc_open(dev_t devno) { gsc_softc_t *sp; int unit = minor(devno); Trace1(2, "gsc_open: open unit %d", unit); if (unit < 0 || unit >= MAX_UNITS) { return (ENODEV); } sp = &softinfo[unit]; if (sp->iscfg == 0 || sp->fp == NULL) { Trace2(0, "%d: bad unit (%d)", __LINE__, unit); return (ENODEV); } simple_lock(&sp->dd_lock); if (sp->isopen) { simple_unlock(&sp->dd_lock); return (EBUSY); } sp->isopen = 1; simple_unlock(&sp->dd_lock); return (0); }
/* * Shut down a device */ static void gsclose(gsc_softc_t *sp, dev_t devno) { int i; if (sp->fp != NULL && sp->unstart) { (void) fp_ioctl(sp->fp, SCIOSTOP, (caddr_t) IDLUN(sp->tgt, sp->lun), NULL); sp->unstart = 0; } if (sp->fp) { (void) fp_close(sp->fp); sp->fp = NULL; } for (i = 0; i < MAX_UNITS; i++) { if (softinfo[i].iscfg) { Trace1(0, "gsclose: unit %d still confd", i); break; } } if (i == MAX_UNITS) { Trace0(0, "gsclose: All unconfigured now"); (void) devswdel(devno); unpincode((int (*) ()) gscdd_intr); } }
/******************************************************************** XmlReportParseError - *********************************************************************/ static void XmlReportParseError( __in IXMLDOMParseError* pixpe ) { HRESULT hr = S_OK; long lNumber = 0; BSTR bstr = NULL; Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:"); hr = pixpe->get_errorCode(&lNumber); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode."); Trace1(REPORT_STANDARD, "errorCode = 0x%x", lNumber); hr = pixpe->get_filepos(&lNumber); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos."); Trace1(REPORT_STANDARD, "filepos = %d", lNumber); hr = pixpe->get_line(&lNumber); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.line."); Trace1(REPORT_STANDARD, "line = %d", lNumber); hr = pixpe->get_linepos(&lNumber); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos."); Trace1(REPORT_STANDARD, "linepos = %d", lNumber); hr = pixpe->get_reason(&bstr); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason."); Trace1(REPORT_STANDARD, "reason = %ls", bstr); ReleaseNullBSTR(bstr); hr = pixpe->get_srcText (&bstr); ExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText ."); Trace1(REPORT_STANDARD, "srcText = %ls", bstr); ReleaseNullBSTR(bstr); LExit: ReleaseBSTR(bstr); }
HRESULT InitSystemMetricValues(THREADSTATE* pts) { HIGHCONTRAST hc; HFONT hfontOld; TEXTMETRIC tm; InterlockedIncrement(&g_cMetricChange); if(!pts->hdcDesktop) { pts->hdcDesktop = CreateCompatibleDC(NULL); if(!pts->hdcDesktop) { RRETURN(E_OUTOFMEMORY); } } _afxGlobalData._sizePixelsPerInch.cx = GetDeviceCaps(pts->hdcDesktop, LOGPIXELSX); _afxGlobalData._sizePixelsPerInch.cy = GetDeviceCaps(pts->hdcDesktop, LOGPIXELSY); g_sizeDragMin.cx = GetSystemMetrics(SM_CXDRAG); g_sizeDragMin.cy = GetSystemMetrics(SM_CYDRAG); _afxGlobalData._sizeScrollbar.cx = GetSystemMetrics(SM_CXVSCROLL); _afxGlobalData._sizeScrollbar.cy = GetSystemMetrics(SM_CYHSCROLL); _afxGlobalData._sizelScrollbar.cx = HimetricFromHPix(_afxGlobalData._sizeScrollbar.cx); _afxGlobalData._sizelScrollbar.cy = HimetricFromVPix(_afxGlobalData._sizeScrollbar.cy); // System font info hfontOld = (HFONT)SelectObject(pts->hdcDesktop, GetStockObject(SYSTEM_FONT)); if(hfontOld) { GetTextMetrics(pts->hdcDesktop, &tm); g_sizeSystemChar.cx = tm.tmAveCharWidth; g_sizeSystemChar.cy = tm.tmHeight; SelectObject(pts->hdcDesktop, hfontOld); } else { g_sizeSystemChar.cx = g_sizeSystemChar.cy = 10; } // Locale info _afxGlobalData._cpDefault = GetACP(); _afxGlobalData._lcidUserDefault = GetSystemDefaultLCID(); // Set Global Locale ID GetSystemNumberSettings(&_afxGlobalData._iNumShape, &_afxGlobalData._uLangNationalDigits); // Accessibility info SystemParametersInfo(SPI_GETSCREENREADER, 0, &g_fScreenReader, FALSE); memset(&hc, 0, sizeof(HIGHCONTRAST)); hc.cbSize = sizeof(HIGHCONTRAST); if(SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST), &hc, 0)) { _afxGlobalData._fHighContrastMode = !!(hc.dwFlags & HCF_HIGHCONTRASTON); } else { Trace1("SPI failed with error %x\n", GetLastError()); } RRETURN(S_OK); }
HRESULT RssUpdateTryLaunchUpdate( __in LPCWSTR wzAppId, __in DWORD64 dw64AppVersion, __out HANDLE* phUpdateProcess, __out_opt DWORD64* pdw64NextUpdateTime ) { HRESULT hr = S_OK; DWORD64 dw64NextUpdateTime = 0; BOOL fUpdateReady = FALSE; DWORD64 dw64UpdateVersion = 0; LPWSTR pwzLocalFeedPath = NULL; LPWSTR pwzLocalSetupPath = NULL; STARTUPINFOW startupInfo = {0}; PROCESS_INFORMATION procInfo = {0}; // If an update is available and higher version that the application currently on the local // machine, launch the install. hr = RssUpdateGetUpdateInfo(wzAppId, &dw64NextUpdateTime, &fUpdateReady, &dw64UpdateVersion, &pwzLocalFeedPath, &pwzLocalSetupPath); if (SUCCEEDED(hr) && fUpdateReady) { if (dw64AppVersion < dw64UpdateVersion) { Trace1(REPORT_DEBUG, "Launching a previously downloaded update at %ls.", pwzLocalSetupPath); if (!::CreateProcessW(NULL, pwzLocalSetupPath, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &procInfo)) { ExitWithLastError1(hr, "Failed to execute %S.", pwzLocalSetupPath); } RssUpdateDeleteUpdateInfo(wzAppId); ExitFunction(); } else // update is not newer, ignore it and continue normally { RssUpdateSetUpdateInfo(wzAppId, dw64NextUpdateTime, 0, NULL, NULL); } } if (pdw64NextUpdateTime) { *pdw64NextUpdateTime = dw64NextUpdateTime; } *phUpdateProcess = procInfo.hProcess; procInfo.hProcess = NULL; LExit: if (procInfo.hThread) { ::CloseHandle(procInfo.hThread); } if (procInfo.hProcess) { ::CloseHandle(procInfo.hProcess); } ReleaseStr(pwzLocalSetupPath); ReleaseStr(pwzLocalFeedPath); return hr; }
int gsc_config(dev_t devno, int cmd, struct uio * uiop) { struct gsc_ddsinfo ddsinfo; gsc_softc_t *sp; int result, i, unit; extern int nodev(); static struct devsw gsc_dsw = { gsc_open, /* entry point for open routine */ gsc_close, /* entry point for close routine */ nodev, /* entry point for read routine */ nodev, /* entry point for write routine */ gsc_ioctl, /* entry point for ioctl routine */ nodev, /* entry point for strategy routine */ 0, /* pointer to tty device structure */ nodev, /* entry point for select routine */ gsc_config, /* entry point for config routine */ nodev, /* entry point for print routine */ nodev, /* entry point for dump routine */ nodev, /* entry point for mpx routine */ nodev, /* entry point for revoke routine */ NULL, /* pointer to device specific data */ NULL, /* select pointer */ DEV_MPSAFE }; if (lockl(&config_lock, LOCK_SHORT) != LOCK_SUCC) { return (EINVAL); } unit = minor(devno); if (unit < 0 || unit >= MAX_UNITS) { Trace2(0, "%d: bad unit %d", __LINE__, unit); result = EINVAL; unlockl(&config_lock); return (result); } switch (cmd) { case CFG_INIT: Trace2(2, "CFG_INIT: unit %d nunit %d\n", unit, nunits); /* * Initialize softinfo, first time around. */ if (nunits == 0) { memset(softinfo, 0, sizeof (softinfo)); } /* * Copy in DDS information */ uiomove((caddr_t) &ddsinfo, sizeof ddsinfo, UIO_WRITE, uiop); sp = &softinfo[unit]; if (sp->iscfg) { Trace1(0, "CFG_INIT: unit %d already configd", unit); result = EBUSY; break; } lock_alloc(&sp->dd_lock, LOCK_ALLOC_PIN, DD_LOCK, -1); lock_alloc(&sp->buf_lock, LOCK_ALLOC_PIN, DD_LOCK, -1); simple_lock_init(&sp->dd_lock); sp->dev = ddsinfo.busid; sp->tgt = ddsinfo.target; sp->lun = ddsinfo.lun; sp->cbuf.index = sp->rbuf.index = unit; /* * If this is the first time through: * Add entry to the device switch table to call this driver * Pin driver code. */ if (nunits == 0) { result = devswadd(devno, &gsc_dsw); if (result != 0) { Trace1(0, "CFG_INIT: devswadd result: %d", result); break; } result = pincode((int (*) ()) gscdd_intr); if (result) { Trace1(0, "CFG_INIT: pincode result: %d", result); devswdel(devno); break; } } sp->iscfg = 1; result = gsopen(sp); if (result) { Trace2(0, "CFG_INIT: gsopen returns %d for unit %d", result, unit); sp->iscfg = 0; gsclose(sp, devno); break; } if (nunits <= unit) nunits = unit + 1; sp->iscfg = 1; break; case CFG_TERM: Trace1(2, "CFG_TERM unit %d", unit); result = 0; sp = &softinfo[unit]; if (sp->iscfg == 0) { Trace1(0, "CFG_TERM: unit %d not already configd", unit); result = ENXIO; break; } else if (sp->isopen) { Trace1(0, "CFG_TERM: unit %d open", unit); result = EBUSY; break; } sp->iscfg = 0; /* block further actions */ gsclose(sp, devno); break; default: result = EINVAL; break; } unlockl(&config_lock); return (result); }
void CDataStream::DumpStreamInfo() { HRESULT hr; LARGEINT ib; STATSTG stat = { 0 }; BYTE* pBytes = NULL; BOOL fHaveCurrent = FALSE; _pStream->Stat(&stat, 0); Trace1("Dumping Stream at 0x%x", _pStream); Trace1(" pwcsName=%ws", stat.pwcsName?stat.pwcsName:L"<no name>"); Trace2(" cbSize(LowPart)=0x%x, cbSize(HighPart)=0x%x\n", stat.cbSize.LowPart, stat.cbSize.HighPart); if(stat.pwcsName) { CoTaskMemFree(stat.pwcsName); } // Get the current position of the stream into ib hr = _pStream->Seek(LI_ZERO.li, STREAM_SEEK_CUR, &ib.uli); if(hr) { goto Cleanup; } fHaveCurrent = TRUE; // Reset the stream to the beginning hr = _pStream->Seek(LI_ZERO.li, STREAM_SEEK_SET, NULL); if(hr) { goto Cleanup; } // BUGBUG: use the metered memory functions. pBytes = (BYTE*)LocalAlloc(LPTR, stat.cbSize.LowPart); if(!pBytes) { goto Cleanup; } hr = _pStream->Read(pBytes, stat.cbSize.LowPart, NULL); if(hr) { goto Cleanup; } Trace1(" Data at start of stream: >>>%.80s<<<", pBytes); Trace1(" Data at end of stream: >>>%.80s<<<\n", max(pBytes+stat.cbSize.LowPart-80, pBytes)); Cleanup: // Restore the position of the stream if(fHaveCurrent) { _pStream->Seek(ib.li, STREAM_SEEK_SET, NULL); } if(pBytes) { LocalFree(pBytes); } return; }
int __cdecl wmain( __in int argc, __in WCHAR * argv[] ) { HRESULT hr = S_OK; LPWSTR pwzCommandLine = NULL; LPWSTR wzAppId = NULL; GUID guidApp; DWORD64 dw64Version; LPWSTR pwzFeedUri = NULL; LPWSTR pwzApplicationPath = NULL; LPWSTR pwzApplicationDirectory = NULL; DWORD64 dw64NextUpdateTime = 0; BOOL fUpdateReady = FALSE; DWORD64 dw64UpdateVersion = 0; LPWSTR pwzFeedPath = NULL; LPWSTR pwzSetupPath = NULL; DWORD dwTimeToLive = 0; LPWSTR pwzApplicationId = NULL; LPWSTR pwzApplicationSource = NULL; BOOL bDeleteUpdateInfoPath = FALSE; BOOL bDeleteUpdateBinaryPath = FALSE; HANDLE hProcess = INVALID_HANDLE_VALUE; HANDLE hUpdateMutex = INVALID_HANDLE_VALUE; // // Process command-line arguments. // for (int i=1; i<argc; i++) { if (argv[i][0] == L'-' || argv[i][0] == L'/') { if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"ac", -1)) { if (wzAppId) { ExitOnFailure(hr = E_INVALIDARG, "May only specify one -ac switch."); } wzAppId = argv[++i]; hr = ::CLSIDFromString(wzAppId, &guidApp); ExitOnFailure(hr, "Failed to parse the -ac argument."); } } else { ExitOnFailure1(hr = E_INVALIDARG, "Bad commandline argument: %S", argv[i]); } } ExitOnNull(wzAppId, hr, E_INVALIDARG, "Must specify a -ac switch."); hr = GetUpdateMutex(&guidApp, &hUpdateMutex); if (FAILED(hr)) { TraceError(hr, "Failed to query the update mutex. Proceeding as if this process didn't acquire the mutex."); } hr = RssUpdateGetAppInfo(wzAppId, &dw64Version, &pwzFeedUri, &pwzApplicationPath); ExitOnFailure(hr, "Failed to get app info."); // If we acquired the update lock and there is already an update downloaded, install that now. if (INVALID_HANDLE_VALUE != hUpdateMutex) { Trace(REPORT_DEBUG, "Got the update mutex. Will check for updates on local machine before launching app."); // If an update is available and higher version that the application currently on the local // machine, launch the install and bail. hr = RssUpdateTryLaunchUpdate(wzAppId, dw64Version, &hProcess, &dw64NextUpdateTime); if (SUCCEEDED(hr)) { if (hProcess) { ::CloseHandle(hProcess); ExitFunction(); // bail since we're doing an update } } } else { Trace(REPORT_DEBUG, "Didn't get the update mutex. Won't check for updates."); } hr = PathExpand(&pwzCommandLine, pwzApplicationPath, PATH_EXPAND_FULLPATH); ExitOnFailure(hr, "Failed to expand application path."); if (pwzCommandLine && L'\"' != pwzCommandLine[0]) { // Get the working directory. hr = PathGetDirectory(pwzCommandLine, &pwzApplicationDirectory); ExitOnFailure(hr, "Failed to get application directory from command-line."); // Put quotes around the command line. hr = StrAllocPrefix(&pwzCommandLine, L"\"", 0); ExitOnFailure(hr, "Failed to prefix command-line with quote."); hr = StrAllocConcat(&pwzCommandLine, L"\"", 0); ExitOnFailure(hr, "Failed to concat command-line with quote."); } Trace1(REPORT_DEBUG, "Launching the target app with commandline: %ls.", pwzCommandLine); hr = LaunchTarget(pwzCommandLine, pwzApplicationDirectory, &hProcess); ExitOnFailure1(hr, "Failed to launch %ls", pwzCommandLine); // If we acquired the update lock then check to see if enough time has passed such that we look for more updates. if (INVALID_HANDLE_VALUE != hUpdateMutex) { hr = RssUpdateCheckFeed(wzAppId, dw64Version, pwzFeedUri, dw64NextUpdateTime); hr = S_OK; } LExit: if (INVALID_HANDLE_VALUE != hUpdateMutex) { ::CloseHandle(hUpdateMutex); } if (INVALID_HANDLE_VALUE != hProcess) { ::CloseHandle(hProcess); } if (bDeleteUpdateInfoPath) { ::DeleteFileW(pwzFeedPath); } if (bDeleteUpdateBinaryPath) { ::DeleteFileW(pwzSetupPath); } ReleaseStr(pwzApplicationSource); ReleaseStr(pwzApplicationId); ReleaseStr(pwzSetupPath); ReleaseStr(pwzFeedPath); ReleaseStr(pwzApplicationPath); ReleaseStr(pwzFeedUri); ReleaseStr(pwzCommandLine); ReleaseStr(pwzApplicationDirectory); return SCODE_CODE(hr); }