/* * Validate that devno is indeed for a SCSI adapter, and set up stuff for it. */ static int gsopen(gsc_softc_t * sp) { struct file *fp; int r; struct devinfo di; Trace2(2, "gsopen: %d.%d", major(sp->dev), minor(sp->dev)); sp->fp = NULL; r = fp_opendev(sp->dev, DREAD|DWRITE|DKERNEL, NULL, 0, &fp); if (r) { Trace3(0, "%d: fp_opendev unit %d=%d", __LINE__, sp->cbuf.index, r); return (r); } r = fp_ioctl(fp, IOCINFO, (caddr_t) &di, NULL); if (r) { Trace3(0, "%d: fp_ioctl unit %d=%d", __LINE__, sp->cbuf.index, r); (void) fp_close(fp); return (r); } if (di.devtype != DD_BUS || di.devsubtype != DS_SCSI) { Trace2(0, "%d: not SCSI bus on unit %d", __LINE__, sp->cbuf.index); (void) fp_close(fp); return (r); } sp->fp = fp; sp->unstart = 1; if (fp_ioctl(sp->fp, SCIOSTART, (caddr_t) IDLUN(sp->tgt, sp->lun), NULL)) { sp->unstart = 0; } 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); }
LRESULT CALLBACK mHpWebClient::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SIZE: { mHpWebClient* win = reinterpret_cast<mHpWebClient*> (::GetWindowLongPtr(hwnd, GWLP_USERDATA)); if (win) { win->Resize(LOWORD(lParam), HIWORD(lParam)); } return 0; } case WM_CREATE: { return 0; } case WM_KEYDOWN: { TraceFunc("WM_KEYDOWN in mHpWebClient"); Trace2("wParam: ", wParam); if (wParam == VK_TAB) { /* The following code is necessary to enable 'tabulator navigating' in forms. See also http://www.microsoft.com/0499/faq/faq0499.asp and the SendMessage part in the MessageLoop */ IOleInPlaceActiveObject* ipao; IWebBrowser2 *webBrowser2; mHpWebClient* win = reinterpret_cast<mHpWebClient*> (::GetWindowLongPtr(hwnd, GWLP_USERDATA)); if (win) { if (!win->browserObject_->QueryInterface(IID_IWebBrowser2, (void**)&webBrowser2)) { webBrowser2->QueryInterface(IID_IOleInPlaceActiveObject, reinterpret_cast<void**>(&ipao)); if (ipao) { MSG m; m.message=WM_KEYDOWN; m.wParam = wParam; m.lParam = lParam; m.hwnd = hwnd; ipao->TranslateAccelerator(&m); } else { ::MessageBox(0, "Failed to retrieve IOleInPlaceActiveObject in WM_KEYDOWN", 0, 0); } } return 0; } else { ::MessageBox(0, "Failed to retrieve webBrowser2 in WM_KEYDOWN", 0, 0); } return -1; } break; } case WM_APP: { TraceFunc("WM_APP called"); mHpWebClient* win = reinterpret_cast<mHpWebClient* >(::GetWindowLongPtr(hwnd, GWLP_USERDATA)); std::string* path_with_params = reinterpret_cast<std::string*>(wParam); std::string path; std::map<std::string,std::string> params; Trace(std::string("path_with_params: ") + *path_with_params); SplitGetReq(*path_with_params, path, params); Trace(std::string("path: ") + path); std::string out_html; win->AppLink(path, out_html, params); win->HTML(out_html); // url is allocated in DOCHostHandler.cpp Trace("going to delete url"); //delete url; delete path_with_params; // param_map is allocated in DOCHostHandler.cpp Trace("going to delete param_map"); //delete param_map; Trace("param_map deleted"); return 0; } } return(DefWindowProc(hwnd, uMsg, wParam, lParam)); }
// See also: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm/chap6_7zdz.asp HRESULT mHpWebClient::Invoke( DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid */ , WORD /*wFlags */ , DISPPARAMS FAR* pDispParams , VARIANT FAR* /*pVarResult */ , EXCEPINFO FAR* /*pExcepInfo */ , unsigned int FAR* /*puArgErr */ ) { /* _______________ From ExDispid.h ---===============--- The constants passed through dispIdMember seem to be defined in ExDispId.h. However, in the MinGw distribution, only a few are defined, much less than in Microsofts Platform SDK. So, I am defininig those that I need here.... */ #define DISPID_BEFORENAVIGATE 100 // this is sent before navigation to give a chance to abort #define DISPID_COMMANDSTATECHANGE 105 #define DISPID_NAVIGATECOMPLETE2 252 // UIActivate new document #define DISPID_NAVIGATEERROR 271 // Fired to indicate the a binding error has occured #define DISPID_DOWNLOADCOMPLETE 104 #define DISPID_DOWNLOADBEGIN 106 #define DISPID_PROPERTYCHANGE 112 // sent when the PutProperty method is called #define DISPID_SETSECURELOCKICON 269 // sent to suggest the appropriate security icon to show //#define DISPID_PROGRESSCHANGE 108 // sent when download progress is updated switch (dispIdMember) { case DISPID_BEFORENAVIGATE : // this is sent before navigation to give a chance to abort ::MessageBox(0, "Before Navigate", 0, 0); return S_OK; break; // case DISPID_NAVIGATECOMPLETE : // in async, this is sent when we have enough to show // // ::MessageBox(0, "Download complete", 0, 0); // break; case DISPID_STATUSTEXTCHANGE : //case DISPID_QUIT : case DISPID_DOWNLOADCOMPLETE: return S_OK; case DISPID_COMMANDSTATECHANGE : return S_OK; break; case DISPID_DOWNLOADBEGIN : return S_OK; break; //case DISPID_NEWWINDOW : // sent when a new window should be created case DISPID_PROGRESSCHANGE : // sent when download progress is updated //case DISPID_WINDOWMOVE : // sent when main window has been moved //case DISPID_WINDOWRESIZE : // sent when main window has been sized //case DISPID_WINDOWACTIVATE : // sent when main window has been activated case DISPID_PROPERTYCHANGE: { // sent when the PutProperty method is called VARIANT a = pDispParams->rgvarg[0]; return S_OK; } case DISPID_TITLECHANGE : // sent when the document title changes //case DISPID_TITLEICONCHANGE : // sent when the top level window icon may have changed. //case DISPID_FRAMEBEFORENAVIGATE : //case DISPID_FRAMENAVIGATECOMPLETE : //case DISPID_FRAMENEWWINDOW : return S_OK; break; // DISPID_BEFORENAVIGATE2 replaces BeforeNavigate and FrameBeforeNavigate. These should not be // used anymore. case DISPID_BEFORENAVIGATE2: { // hyperlink clicked on TraceFunc("DWebBrowserEvents2::BeforeNavigate2 "); VARIANT vURL_p = pDispParams->rgvarg[5]; VARIANT vURL = *(vURL_p.pvarVal); VARIANT vCANCEL = pDispParams->rgvarg[0]; std::string type = VariantTypeAsString(vCANCEL); std::wstring ws_url = vURL.bstrVal; std::string url = ws2s(ws_url); Trace2("url=", url); if (BeforeNavigate(url, pDispParams)) { *(vCANCEL.pboolVal) = VARIANT_FALSE; } else { *(vCANCEL.pboolVal) = VARIANT_TRUE; VARIANT vDisp = pDispParams->rgvarg[6]; IDispatch* disp=vDisp.pdispVal; IWebBrowser2* webBrowser; disp->QueryInterface(IID_IWebBrowser2, reinterpret_cast<void**>(&webBrowser)); webBrowser->Stop(); } return S_OK; } break; case DISPID_NEWWINDOW2: return S_OK; case DISPID_NAVIGATECOMPLETE2: // UIActivate new document return S_OK; break; //case DISPID_ONQUIT : //case DISPID_ONVISIBLE : // sent when the window goes visible/hidden //case DISPID_ONTOOLBAR : // sent when the toolbar should be shown/hidden //case DISPID_ONMENUBAR : // sent when the menubar should be shown/hidden //case DISPID_ONSTATUSBAR : // sent when the statusbar should be shown/hidden //case DISPID_ONFULLSCREEN : // sent when kiosk mode should be on/off case DISPID_DOCUMENTCOMPLETE : // new document goes ReadyState_Complete //AddSink(); return S_OK; //case DISPID_ONTHEATERMODE : // sent when theater mode should be on/off //case DISPID_ONADDRESSBAR : // sent when the address bar should be shown/hidden //case DISPID_WINDOWSETRESIZABLE : // sent to set the style of the host window frame //case DISPID_WINDOWCLOSING : // sent before script window.close closes the window //case DISPID_WINDOWSETLEFT : // sent when the put_left method is called on the WebOC //case DISPID_WINDOWSETTOP : // sent when the put_top method is called on the WebOC //case DISPID_WINDOWSETWIDTH : // sent when the put_width method is called on the WebOC //case DISPID_WINDOWSETHEIGHT : // sent when the put_height method is called on the WebOC //case DISPID_CLIENTTOHOSTWINDOW : // sent during window.open to request conversion of dimensions //case DISPID_SETSECURELOCKICON : // sent to suggest the appropriate security icon to show //case DISPID_FILEDOWNLOAD : // Fired to indicate the File Download dialog is opening case DISPID_NAVIGATEERROR: { // Fired to indicate the a binding error has occured char buf[200]; VARIANT StatusCode=*((pDispParams->rgvarg[1]).pvarVal); sprintf(buf, "Navigate Error, code is: %d", static_cast<int>(StatusCode.lVal)); MessageBox(0, buf, 0, 0); //case DISPID_PRIVACYIMPACTEDSTATECHANGE : // Fired when the user's browsing experience is impacted return S_OK; } default: char buf[50]; sprintf(buf, "invoke, dispid: %d", static_cast<int>(dispIdMember)); if (TODO_bool) ::MessageBox(0, buf, 0, 0); return DISP_E_MEMBERNOTFOUND; } }
HRESULT RssUpdateCheckFeed( __in LPCWSTR wzAppId, __in DWORD64 dw64AppVersion, __in LPCWSTR wzFeedUri, __in DWORD64 dw64NextUpdateTime ) { HRESULT hr = S_OK; FILETIME ft; LPWSTR pwzLocalFeedPath = NULL; LPWSTR pwzLocalSetupPath = NULL; DWORD dwTimeToLive = 0; LPWSTR pwzApplicationId = NULL; DWORD64 dw64UpdateVersion = 0; LPWSTR pwzApplicationSource = NULL; BOOL fDeleteDownloadedFeed = FALSE; BOOL fDeleteDownloadedSetup = FALSE; ::GetSystemTimeAsFileTime(&ft); DWORD64 dw64CurrentTime = (static_cast<DWORD64>(ft.dwHighDateTime ) << 32) + ft.dwLowDateTime; if (dw64NextUpdateTime < dw64CurrentTime) { hr = StrAlloc(&pwzLocalFeedPath, MAX_PATH); ExitOnFailure(hr, "Failed to allocate feed path string.") hr = DirCreateTempPath(L"CT", pwzLocalFeedPath, MAX_PATH); ExitOnFailure(hr, "Failed to get a temp file path for the update info."); fDeleteDownloadedFeed = TRUE; hr = Download(NULL, wzFeedUri, pwzLocalFeedPath); ExitOnFailure2(hr, "Failed to download from %ls to %ls.", wzFeedUri, pwzLocalFeedPath); hr = RssUpdateGetFeedInfo(pwzLocalFeedPath, &dwTimeToLive, &pwzApplicationId, &dw64UpdateVersion, &pwzApplicationSource); ExitOnFailure1(hr, "Failed to ReadUpdateInfo from %ls.", pwzLocalFeedPath); if (dw64AppVersion < dw64UpdateVersion) { hr = StrAlloc(&pwzLocalSetupPath, MAX_PATH); ExitOnFailure(hr, "Failed to allocate setup path string.") // Get a filename for the update. hr = DirCreateTempPath(L"CT", pwzLocalSetupPath, MAX_PATH); ExitOnFailure(hr, "Failed to get a temp file path for the update binary."); // Download the udpate. fDeleteDownloadedSetup = TRUE; hr = Download(wzFeedUri, pwzApplicationSource, pwzLocalSetupPath); ExitOnFailure2(hr, "Failed to download from %ls to %ls.", pwzApplicationSource, pwzLocalSetupPath); Trace2(REPORT_DEBUG, "Downloaded from %ls to %ls.", pwzApplicationSource, pwzLocalSetupPath); Trace(REPORT_DEBUG, "Queueing update for next launch."); // Queue the update for discovery at the next launch. fDeleteDownloadedFeed = FALSE; fDeleteDownloadedSetup = FALSE; ::GetSystemTimeAsFileTime(&ft); dw64NextUpdateTime = (static_cast<DWORD64>(ft.dwHighDateTime ) << 32) + ft.dwLowDateTime + dwTimeToLive; RssUpdateSetUpdateInfo(wzAppId, dw64NextUpdateTime, dw64UpdateVersion, pwzLocalFeedPath, pwzLocalSetupPath); if (0 != lstrcmpW(pwzApplicationId, wzAppId)) { RssUpdateSetUpdateInfo(pwzApplicationId, dw64NextUpdateTime, 0, NULL, NULL); } } } else { Trace(REPORT_DEBUG, "Skipped update check because feed 'time to live' has not expired."); } LExit: if (fDeleteDownloadedSetup) { ::DeleteFileW(pwzLocalSetupPath); } if (fDeleteDownloadedFeed) { ::DeleteFileW(pwzLocalFeedPath); } ReleaseStr(pwzApplicationSource); ReleaseStr(pwzApplicationId); ReleaseStr(pwzLocalSetupPath); ReleaseStr(pwzLocalFeedPath); return hr; }
static int gsccmd(dev_t dev, scmd_t *argcmd, ulong dflag) { gsc_softc_t *sp; scmd_t local, *l; char sbyte, albits; struct sc_buf *usc; struct buf *Ubp; int r, r2, ival, upin, unit, rqvalid, once; unit = minor(dev); Trace2(1, "%d: cmd for unit %d", __LINE__, minor(dev)); if (unit < 0 || unit >= MAX_UNITS) { setuerror(ENXIO); return (ENXIO); } sp = &softinfo[unit]; if (sp->iscfg == 0 || sp->fp == NULL) { Trace2(0, "gsccmd: bad unit %d (cfg=%d)", unit, sp->iscfg); r = ENODEV; setuerror(r); return (r); } simple_lock(&sp->dd_lock); l = &local; if (dflag & DKERNEL) { l = argcmd; } else { r = copyin((caddr_t) argcmd, (caddr_t) l, sizeof (scmd_t)); if (r != 0) { Trace2(0, "%d: copyin=%d", __LINE__, r); setuerror(r); MJ_RTN (r); } } Trace6(1, "%d: cdblen%d datalen%d snslen%d rw=%d tv=%d", __LINE__, l->cdblen, l->datalen, l->senselen, l->rw, l->timeval); sbyte = 0; rqvalid = upin = r = r2 = 0; usc = &sp->cmdbuf; Ubp = &usc->bufstruct; memset(usc, 0, sizeof (struct sc_buf)); /* * Check some parameters... */ if (l->cdblen > sizeof (struct sc_cmd)) { r = EINVAL; goto out; } /* * Setup sc_buf structure */ Ubp->b_iodone = gscdd_intr; Ubp->b_dev = sp->dev; Ubp->b_flags = B_BUSY | B_MPSAFE; Ubp->b_resid = Ubp->b_bcount = l->datalen; Ubp->b_xmemd.aspace_id = XMEM_INVAL; Ubp->b_event = EVENT_NULL; if (l->datalen) { Ubp->b_un.b_addr = l->data_buf; if (l->rw) { Ubp->b_flags |= B_READ; } if (dflag & DKERNEL) { r = pinu(l->data_buf, l->datalen, UIO_SYSSPACE); } else { r = pinu(l->data_buf, l->datalen, UIO_USERSPACE); } if (r) { Trace2(0, "%d: pinu buf %d", __LINE__, r); goto out; } upin++; if (dflag & DKERNEL) { r = xmattach(l->data_buf, l->datalen, &Ubp->b_xmemd, SYS_ADSPACE); } else { r = xmattach(l->data_buf, l->datalen, &Ubp->b_xmemd, USER_ADSPACE); } if (r != XMEM_SUCC) { Trace2(0, "%d: xmattach %d", __LINE__, r); r = EFAULT; goto out; } upin++; r = xmemdma(&Ubp->b_xmemd, l->data_buf, XMEM_UNHIDE); if (r == XMEM_FAIL) { Trace2(0, "%d: xmemdma %d", __LINE__, r); r = EFAULT; goto out; } r = 0; } usc->scsi_command.scsi_id = sp->tgt; usc->scsi_command.scsi_length = l->cdblen; if (dflag & DKERNEL) { bcopy(l->cdb, (caddr_t)&usc->scsi_command.scsi_cmd, l->cdblen); } else { r = copyin(l->cdb, (caddr_t) & usc->scsi_command.scsi_cmd, l->cdblen); if (r != 0) { goto out; } } /* Setting lun in SCSI CDB as well as sc_buf structure */ usc->lun = sp->lun; usc->scsi_command.scsi_cmd.lun &= 0x1F; usc->scsi_command.scsi_cmd.lun |= (sp->lun << 5) & 0xE0; albits = usc->scsi_command.scsi_cmd.lun; usc->timeout_value = l->timeval; if (sp->needresume) { usc->flags |= SC_RESUME; sp->needresume = 0; } if (scudebug > 1) { char *c = (char *) &usc->scsi_command.scsi_cmd; char cdbuf[64]; (void) sprintf(cdbuf, "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x " "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11]); Trace2(0, "%d: cdb=%s", __LINE__, cdbuf); } once = 0; again: Ubp->b_flags &= ~B_DONE; r = devstrat(Ubp); if (r == 0) { ival = disable_lock(INTCLASS1, &sp->buf_lock); while ((Ubp->b_flags & B_DONE) == 0) { e_sleep_thread(&Ubp->b_event, &sp->buf_lock, LOCK_HANDLER); } unlock_enable(ival, &sp->buf_lock); } else { /* * If ENXIO, We never actually got started. */ if (r == ENXIO && once == 0) { once++; usc->flags |= SC_RESUME|SC_DELAY_CMD; goto again; } sp->needresume = 1; Trace2(1, "%d: devstrat=%d", __LINE__, r); goto out; } Trace4(1, "%d: b_flags %x b_error %d b_resid %d", __LINE__, Ubp->b_flags, Ubp->b_error, Ubp->b_resid); Trace5(1, "%d: sv %x st %x gc %x as %x", __LINE__, usc->status_validity, usc->scsi_status, usc->general_card_status, usc->adap_q_status); if (Ubp->b_flags & B_ERROR) { r = Ubp->b_error; sp->needresume = 1; } if (usc->status_validity & SC_SCSI_ERROR) { sbyte = (usc->scsi_status & SCSI_STATUS_MASK); sp->needresume = 1; if (sbyte == SC_CHECK_CONDITION && l->senselen) { struct sc_buf *usl; struct buf *Sbp; r = make_rqs(sp, albits, l->sense_buf, l->senselen, (dflag & DKERNEL) != 0); if (r) { Trace2(0, "%d: make_rqs=%d", __LINE__, r); goto out; } usl = &sp->rqsbuf; Sbp = &usl->bufstruct; r = devstrat(Sbp); if (r == 0) { ival = disable_lock(INTCLASS1, &sp->buf_lock); while ((Sbp->b_flags & B_DONE) == 0) { e_sleep_thread(&Sbp->b_event, &sp->buf_lock, LOCK_HANDLER); } unlock_enable(ival, &sp->buf_lock); } else { Trace2(0, "%d:ds=%d for rqs", __LINE__, r); goto out; } xmdetach(&Sbp->b_xmemd); if (dflag & DKERNEL) { (void) unpinu(l->sense_buf, l->senselen, UIO_SYSSPACE); } else { (void) unpinu(l->sense_buf, l->senselen, UIO_USERSPACE); } Trace4(1, "%d SENSE: b_flags %x b_error %d b_resid %d", __LINE__, Sbp->b_flags, Sbp->b_error, Sbp->b_resid); Trace5(1, "%d: sv %x st %x gc %x as %x", __LINE__, usl->status_validity, usl->scsi_status, usl->general_card_status, usl->adap_q_status); if (usl->scsi_status || usl->general_card_status) { r = EIO; } else { rqvalid = 1; } } } if (usc->status_validity & SC_ADAPTER_ERROR) { sp->needresume = 1; Trace2(0, "%d: adapter error 0x%x", __LINE__, usc->general_card_status); Ubp->b_flags |= B_ERROR; switch (usc->general_card_status) { case SC_NO_DEVICE_RESPONSE: case SC_HOST_IO_BUS_ERR: case SC_SCSI_BUS_FAULT: case SC_CMD_TIMEOUT: case SC_ADAPTER_HDW_FAILURE: case SC_ADAPTER_SFW_FAILURE: case SC_FUSE_OR_TERMINAL_PWR: case SC_SCSI_BUS_RESET: default: r = EIO; break; } } /* * Log errors through errsave function */ if (usc->status_validity & (SC_SCSI_ERROR|SC_ADAPTER_ERROR)) { struct sc_error_log_df log; memset(&log, 0, sizeof (log)); /* * All errors are 'temporary unknown driver error' */ log.error_id = ERRID_SCSI_ERR6; (void) sprintf(log.resource_name, "gsc%d", unit); memcpy(&log.scsi_command, &usc->scsi_command, sizeof (struct scsi)); log.status_validity = usc->status_validity; log.scsi_status = usc->scsi_status; log.general_card_status = usc->general_card_status; if (rqvalid) { int amt; if (l->senselen > 128) amt = 128; else amt = l->senselen; (void) copyin(l->sense_buf, log.req_sense_data, amt); } errsave(&log, sizeof (struct sc_error_log_df)); } if (dflag & DKERNEL) { *l->statusp = sbyte; } else { r2 = copyout(&sbyte, l->statusp, 1); if (r2 != 0) { if (r == 0) r = r2; goto out; } } out: if (l->datalen) { if (upin > 1) { xmdetach(&Ubp->b_xmemd); upin--; } if (upin > 0) { if (dflag & DKERNEL) { (void) unpinu(l->data_buf, l->datalen, UIO_SYSSPACE); } else { (void) unpinu(l->data_buf, l->datalen, UIO_USERSPACE); } upin--; } } Trace2(1, "%d: returning %d", __LINE__, r); if (r) setuerror(r); MJ_RTN (r); }
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; }