Esempio n. 1
0
bool 
GetPyModuleAndFunctionObjects(  const std::wstring& filename, 
                              const std::string& function,
                              PyObject*& rpModule,
                              PyObject*& rpFunction ) 
{   

    bool rc;
    rpModule = rpFunction = NULL;

    rc = ModuleCache::Factory().GetModule( filename, rpModule );
    if (!rc || !rpModule) {
        ERROUT("Couldn't get python module %s", ASCII_REPR(filename));
        return false;
    }

    // rpFunction is always a new reference; easier than caching it
    rpFunction = PyObject_GetAttrString(rpModule, function.c_str());
    if (!rpFunction || !PyCallable_Check(rpFunction)) {
        if (PyErr_Occurred()) {
            PyErr_Print();
        }
        Py_XDECREF(rpFunction);
        rpModule = rpFunction = NULL; // Don't want to return any handles to the caller if there's a problem
        ERROUT("Cannot find valid function \"%s\" in %s", function.c_str(), ASCII_REPR(filename));
        return false;
    }

    return true;
}
Esempio n. 2
0
static int
puffs_vnop_open(struct vop_open_args *ap)
{
    PUFFS_MSG_VARS(vn, open);
    struct vnode *vp = ap->a_vp;
    struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
    int mode = ap->a_mode;
    int error;

    DPRINTF(("puffs_open: vp %p, mode 0x%x\n", vp, mode));

    if (vp->v_type == VREG && mode & FWRITE && !EXISTSOP(pmp, WRITE))
        ERROUT(EROFS);

    if (!EXISTSOP(pmp, OPEN))
        ERROUT(0);

    PUFFS_MSG_ALLOC(vn, open);
    open_msg->pvnr_mode = mode;
    puffs_credcvt(&open_msg->pvnr_cred, ap->a_cred);
    puffs_msg_setinfo(park_open, PUFFSOP_VN,
                      PUFFS_VN_OPEN, VPTOPNC(vp));

    PUFFS_MSG_ENQUEUEWAIT2(pmp, park_open, vp->v_data, NULL, error);
    error = checkerr(pmp, error, __func__);

out:
    DPRINTF(("puffs_open: returning %d\n", error));
    PUFFS_MSG_RELEASE(open);
    if (error)
        return error;
    return vop_stdopen(ap);
}
Esempio n. 3
0
//===========================================================================
// DIUtilGetJoystickCallout
//
// Retrieves the joystick callout for the specified object.
//
// Parameters:
//  short                   nJoystickId - joystick id
//  LPDIRECTINPUTJOYCONFIG  pdiJoyCfg   - ptr to joyconfig object
//  LPTSTR                  tszCallout  - ptr to string buffer
//  int                     nBugSize    - size of string buffer
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilGetJoystickCallout(short nJoystickId, 
                                    LPDIRECTINPUTJOYCONFIG pdiJoyCfg,
                                    LPTSTR tszCallout, int nBufSize)
{
    HRESULT                 hRes        = E_NOTIMPL;
    DIJOYCONFIG             dijc;

    // validate pointers
    if( (IsBadReadPtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) ||
        (IsBadWritePtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickCallout() - invalid pdiJoyCfg\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)tszCallout, sizeof(TCHAR))) ||
        (IsBadWritePtr((void*)tszCallout, sizeof(TCHAR))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickCallout() - invalid tszCallout\n"));
        return E_POINTER;
    }

    // get the callout
    ZeroMemory(&dijc, sizeof(DIJOYCONFIG));
    dijc.dwSize = sizeof(DIJOYCONFIG);
    hRes = pdiJoyCfg->GetConfig(nJoystickId, &dijc, DIJC_CALLOUT);
    if(FAILED(hRes))
    {       
        LoadString(ghInst, IDS_ERROR, tszCallout, nBufSize);
        return hRes;
    }

#ifndef UNICODE
    // we've compiled for ANSI
    //
    // we need to convert the type name string
    WideCharToMultiByte(CP_ACP, 0, dijc.wszCallout, -1, tszCallout,
        MAX_JOYSTRING, NULL, NULL);
#else
    // we've compiled for UNICODE
    //
    // no conversion needed
    lstrcpy(tszCallout, dijc.wszType);
#endif

    // if there is no callout name, then display a default string
    if(0 == lstrcmp(tszCallout, TEXT("")))
    {
        LoadString(ghInst, IDS_DEFAULT, tszCallout, nBufSize);
    }


    // we're done
    return hRes;

} //*** end DIUtilGetJoystickCallout()
Esempio n. 4
0
//===========================================================================
// DIUtilGetJoystickConfigCLSID
//
// Retrieves the joystick ConfigCLSID for the specified object.
//
// Parameters:
//  short                   nJoystickId - joystick id
//  LPDIRECTINPUTJOYCONFIG  pdiJoyCfg   - ptr to joyconfig object
//  CLSID                   *pclsid     - ptr to store CLSID    
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilGetJoystickConfigCLSID(short nJoystickId, 
                                    LPDIRECTINPUTJOYCONFIG pdiJoyCfg,
                                    CLSID* pclsid)
{
    DIJOYCONFIG dijc;

    // validate pointers
    if( (IsBadReadPtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) ||
        (IsBadWritePtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickConfigCLSID() - invalid pdiJoyCfg\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)pclsid, sizeof(CLSID))) ||
        (IsBadWritePtr((void*)pclsid, sizeof(CLSID))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickConfigCLSID() - invalid pclsid\n"));
        return E_POINTER;
    }

    // get the type name
    ZeroMemory(&dijc, sizeof(dijc));
    dijc.dwSize = sizeof(dijc);

    HRESULT hRes = pdiJoyCfg->GetConfig(nJoystickId, &dijc, DIJC_REGHWCONFIGTYPE);

    if(SUCCEEDED(hRes))
    {       
        DIJOYTYPEINFO  dijti;

        // get the clsid
        ZeroMemory(&dijti, sizeof(&dijti));
        dijti.dwSize = sizeof(dijti);

        hRes = pdiJoyCfg->GetTypeInfo(dijc.wszType, &dijti, DITC_CLSIDCONFIG);
        if(SUCCEEDED(hRes))
        {
            // return the CLSID
            *pclsid = dijti.clsidConfig;
        }
        else
        {
            // return a NULL GUID
            *pclsid = (CLSID)NULL_GUID;
        }

    }

    // we're done
    return hRes;

} //*** end DIUtilGetJoystickConfigCLSID()
Esempio n. 5
0
//===========================================================================
// DIUtilGetJoystickTypeName
//
// Retrieves the joystick type name for the specified object.
//
// Parameters:
//  short                   nJoystickId - joystick id
//  LPDIRECTINPUTJOYCONFIG  pdiJoyCfg   - ptr to joyconfig object
//  LPTSTR                  tszTypeName - ptr to string buffer
//  int                     nBugSize    - size of string buffer
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilGetJoystickTypeName(short nJoystickId, LPDIRECTINPUTJOYCONFIG pdiJoyCfg, LPTSTR tszTypeName, int nBufSize)
{
    DIJOYCONFIG  dijc;

    // validate pointers
    if( (IsBadReadPtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) ||
        (IsBadWritePtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickTypeName() - invalid pdiJoyCfg\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)tszTypeName, sizeof(TCHAR))) ||
        (IsBadWritePtr((void*)tszTypeName, sizeof(TCHAR))) )
    {
        ERROUT(TEXT("DIUtilGetJoystickTypeName() - invalid tszTypeName\n"));
        return E_POINTER;
    }

    // get the type name
    ZeroMemory(&dijc, sizeof(dijc));
    dijc.dwSize = sizeof(dijc);

    HRESULT hRes = pdiJoyCfg->GetConfig(nJoystickId, &dijc, DIJC_REGHWCONFIGTYPE);

    if (SUCCEEDED(hRes))
    {       
#ifndef UNICODE
        // we've compiled for ANSI
        //
        // we need to convert the type name string
        WideCharToMultiByte(CP_ACP, 0, dijc.wszType, -1, tszTypeName, MAX_JOYSTRING, NULL, NULL);
#else
        // we've compiled for UNICODE
        //
        // no conversion needed
        lstrcpy(tszTypeName, dijc.wszType);
#endif
    }
    else 
    {
        LoadString(ghInst, IDS_ERROR, tszTypeName, nBufSize);
        ERROUT (tszTypeName);
    }

    // we're done
    return hRes;

} //*** end DIUtilGetJoystickTypeName()
Esempio n. 6
0
//===========================================================================
// DIUtilPollJoystick
//
// Polls the joystick device and returns the device state.
//
// Parameters:
//  LPDIRECTINPUTDEVICE2    pdiDevice2  - ptr to device object
//  DIJOYSTATE              *pdijs      - ptr to store joystick state
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilPollJoystick(LPDIRECTINPUTDEVICE2 pdiDevice2, DIJOYSTATE *pdijs)
{
    HRESULT hRes    = E_NOTIMPL;

    // validate pointers
    if( (IsBadReadPtr((void*)pdiDevice2, sizeof(IDirectInputDevice2))) ||
        (IsBadWritePtr((void*)pdiDevice2, sizeof(IDirectInputDevice2))) )
    {
        ERROUT(TEXT("DIUtilPollJoystick() - invalid pdiDevice2\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)pdijs, sizeof(DIJOYSTATE))) ||
        (IsBadWritePtr((void*)pdijs, sizeof(DIJOYSTATE))) )
    {
        ERROUT(TEXT("DIUtilPollJoystick() - invalid pdijs\n"));
        return E_POINTER;
    }

    // clear the pdijs memory
    //
    // this way, if we fail, we return no data
    ZeroMemory(pdijs, sizeof(DIJOYSTATE));

    // poll the joystick
    //
    // don't worry if it fails, not all devices require polling
    hRes = pdiDevice2->Poll();
    
    // query the device state
    hRes = pdiDevice2->GetDeviceState(sizeof(DIJOYSTATE), pdijs);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilPollJoystick() - GetDeviceState() failed\n"));
        return hRes;
    }

    // done
    return hRes;

} //*** end DIUtilPollJoystick()
Esempio n. 7
0
//===========================================================================
// DIUtilGetHIDDevice
//
// Helper function to get the file handle of the related HID device
//  LPDIRECTINPUTDEVICE2    pdiDevice2  - ptr to device object
//  PHANDLE                 hDriver     - ptr to recieve device handle
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilGetHIDDevice(LPDIRECTINPUTDEVICE2 pdiDevice2, HANDLE *hDriver)
{                         
    HRESULT hRes    = E_NOTIMPL;
    DIPROPGUIDANDPATH dipgp;

    // validate pointers
    if( (IsBadReadPtr((void*)pdiDevice2, sizeof(IDirectInputDevice2))) ||
        (IsBadWritePtr((void*)pdiDevice2, sizeof(IDirectInputDevice2))) )
    {
        ERROUT(TEXT("DIUtilGetHIDDevice() - invalid pdiDevice2\n"));
        return E_POINTER;
    }

    // Initialize structure
    dipgp.diph.dwSize = sizeof(DIPROPGUIDANDPATH);
    dipgp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    dipgp.diph.dwObj = 0;
    dipgp.diph.dwHow = DIPH_DEVICE;

    // Get the path
    hRes = pdiDevice2->GetProperty(DIPROP_GUIDANDPATH, &dipgp.diph);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilGetHIDDevice() - GetProperty() failed\n"));
        return hRes;
    }

    *hDriver = CreateFile(dipgp.wszPath,
                          GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                          NULL,
                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    if(!hDriver)
    {
        ERROUT(TEXT("DIUtilGetHIDDevice() - Can't open device\n"));
        return E_FAIL;
    }
    return hRes;

} //*** end DIUtilGetHIDDevice()
Esempio n. 8
0
/*------------------------------------------------------------------------------
 * nand interface
 */
static void nand_select_chip(struct mtd_info *mtd, int chipnr)
{
	DBGOUT("%s, chipnr=%d\n", __func__, chipnr);

#if defined(CFG_NAND_OPTIONS)
	struct nand_chip *chip = mtd->priv;
	chip->options |= CFG_NAND_OPTIONS;
#endif

	if (chipnr > 4) {
		ERROUT("not support nand chip index %d\n", chipnr);
		return;
	}

	if (-1 == chipnr) {
		NX_MCUS_SetNFCSEnable(CFALSE);		// nand chip select control disable
	} else {
		NX_MCUS_SetNFBank(chipnr);
		NX_MCUS_SetNFCSEnable(CTRUE);
	}
}
Esempio n. 9
0
/*
 * must be called from start area.
 * get 4 static columns and build a temple on the disc
 */
uint8_t strat_static_columns(uint8_t configuration)
{
	uint8_t err;
	uint8_t col1_present = 0, col4_present = 0;
	uint16_t old_spdd, old_spda;

	DEBUG(E_USER_STRAT, "%s(%d)", __FUNCTION__, configuration);

	strat_get_speed(&old_spdd, &old_spda);

	/* calibrate scanner */
	i2c_sensorboard_scanner_calib();

	i2c_mechboard_mode_harvest();

	/* go straight. total distance is less than 5 meters */
	strat_set_speed(1000, 1000);
	trajectory_d_rel(&mainboard.traj, BIG_DIST);

	/* when y > 50, break */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(500), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);

	/* turn to 90° abs while going forward */
	DEBUG(E_USER_STRAT, "turn now");
	strat_set_speed(1000, 350);
	trajectory_only_a_abs(&mainboard.traj, COLOR_A(90));

	/* when y > 100, check the presence of column 4 */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1000), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);
	if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
		col4_present = 1;
	if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
		col4_present = 1;

	/* when y > 120, check the presence of column 1 */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1200), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);
	if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
		col1_present = 1;
	if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
		col1_present = 1;

	/* when y > 130, break */
	err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1300), TRAJ_FLAGS_STD);
	if (TRAJ_SUCCESS(err)) /* we should not reach end */
		ERROUT(END_ERROR);
	else if (err)
		ERROUT(err);

	strat_infos.s_cols.flags |= STATIC_COL_LINE0_DONE;

	DEBUG(E_USER_STRAT, "col4=%d col1=%d", col4_present, col1_present);
	DEBUG(E_USER_STRAT, "have %d cols", get_column_count());

	if (configuration == 0) {
		if (get_column_count() > 2) {
			configuration = 1;
			if (col4_present || col1_present) {
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}
			else {
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE1_DONE;
			}
		}

		/* only 2 colums on the first line */
		else {
			/* all other colums are on line 1 */
			if (col4_present && col1_present) {
				configuration = 2;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}

			/* only 2 columns on line 1, so there are also
			 * 2 on line 2 */
			else if (col4_present || col1_present) {
				configuration = 4;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE2_DONE;
			}

			/* all other columns are on line 2 */
			else {
				configuration = 3;
				strat_infos.s_cols.flags |= 
					STATIC_COL_LINE1_DONE;
			}
		}
	}

	strat_infos.s_cols.configuration = configuration;
	DEBUG(E_USER_STRAT, "use configuration %d", configuration);

	if (configuration == 1) {
		/* we already got 4 columns, go to the disc directly */

		strat_set_speed(1500, 900);
		trajectory_only_a_abs(&mainboard.traj, COLOR_A(0));
		err = WAIT_COND_OR_TRAJ_END(x_is_more_than(1100), TRAJ_FLAGS_STD);

		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else if (configuration == 2 /* go from line 0 to line 1 */) {
		strat_set_speed(800, 1000);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1300), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
		strat_set_speed(1000, 600);
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1100),
					    TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else if (configuration == 3 /* go from line 0 to line 2 and there is 4 columns
		    on line 2*/) {
		strat_set_speed(1000, 600);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1110), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	} 	
	else if (configuration == 4 /* go from line 0 to line 2 and there is 2 columns
		      on line 2 */) {
		strat_set_speed(1000, 600);
		/* relative is needed here */
		trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
		err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(600), TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
	}
	else {
		trajectory_stop(&mainboard.traj);
	}

	ERROUT(END_TRAJ);

 end:
	strat_set_speed(old_spdd, old_spda);
	return err;
}
Esempio n. 10
0
/*
 * get last 2 columns
 * must be called after the first temple building
 */
uint8_t strat_static_columns_pass2(void)
{
	uint16_t old_spdd, old_spda;
	uint8_t side, err, next_mode;

	DEBUG(E_USER_STRAT, "%s()", __FUNCTION__);

	strat_get_speed(&old_spdd, &old_spda);

	if (get_color() == I2C_COLOR_RED)
		side = I2C_RIGHT_SIDE;
	else
		side = I2C_LEFT_SIDE;

	if (strat_infos.conf.flags & STRAT_CONF_STORE_STATIC2)
		next_mode = I2C_MECHBOARD_MODE_STORE;
	else
		next_mode = I2C_MECHBOARD_MODE_HARVEST;

	switch (strat_infos.s_cols.configuration) {

	/* configuration 1: 4 cols on line 0 */
	case 1:
		if (strat_infos.s_cols.flags & STATIC_COL_LINE1_DONE) {
			/* go on line 2 */

			strat_set_speed(2000, 700);
			trajectory_d_a_rel(&mainboard.traj, -450, COLOR_A(35));
			err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
			if (!TRAJ_SUCCESS(err))
				ERROUT(err);
			
			i2c_mechboard_mode_prepare_pickup_next(side, 
							       next_mode);

			strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
			trajectory_goto_forward_xy_abs(&mainboard.traj,
						       LINE2_X, 
						       COLOR_Y(400));
			err = WAIT_COND_OR_TRAJ_END(get_column_count() == 2,
						    TRAJ_FLAGS_NO_NEAR);
			if (!TRAJ_SUCCESS(err))
				ERROUT(err);
		}
		else {
			/* go on line 1 */
			strat_set_speed(2000, 700);
			trajectory_d_a_rel(&mainboard.traj, -650, COLOR_A(55));
			err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
			if (!TRAJ_SUCCESS(err))
				ERROUT(err);
			
			i2c_mechboard_mode_prepare_pickup_next(side, 
							       next_mode);

			strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);

			err = goto_and_avoid_forward(LINE1_X, 
						     COLOR_Y(400),
						     TRAJ_FLAGS_NO_NEAR,
						     TRAJ_FLAGS_NO_NEAR);
			if (!TRAJ_SUCCESS(err))
				ERROUT(err);
		}

		ERROUT(END_TRAJ);
		break;

	/* configuration 2: 2 cols on line 0,
	   all other colums are on line 1 */
	case 2:
		/* go on line 1 */
		strat_set_speed(2000, 700);
		trajectory_d_a_rel(&mainboard.traj, -410, COLOR_A(-20));
		err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
		if (!TRAJ_SUCCESS(err))
			ERROUT(err);
			
		i2c_mechboard_mode_prepare_pickup_next(side, 
						       next_mode);

		strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);

		err = goto_and_avoid_forward(COL10_X, COLOR_Y(400),
					     TRAJ_FLAGS_NO_NEAR,
					     TRAJ_FLAGS_NO_NEAR);
		if (!TRAJ_SUCCESS(err))
			ERROUT(err);
		
		ERROUT(END_TRAJ);
		break;

	/* configuration 3: 2 cols on line 0,
	   all other colums are on line 2 */
	case 3:
		/* go on line 2 */
		strat_set_speed(2000, 700);
		trajectory_d_a_rel(&mainboard.traj, -150, COLOR_A(-30));
		err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
		if (!TRAJ_SUCCESS(err))
			ERROUT(err);
			
		i2c_mechboard_mode_prepare_pickup_next(side, 
						       next_mode);

		strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);

		trajectory_goto_forward_xy_abs(&mainboard.traj,
					       LINE2_X, 
					       COLOR_Y(400));
		err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
		if (!TRAJ_SUCCESS(err))
			ERROUT(err);

		ERROUT(END_TRAJ);
		break;

	/* configuration 4: 2 cols on line 0,
	   2 on line 1, 2 on line 2 */
	case 4:
		/* go on line 1 */
		strat_set_speed(600, 2000);
		trajectory_d_a_rel(&mainboard.traj, -BIG_DIST,
				   COLOR_A(-135));
		err = WAIT_COND_OR_TRAJ_END(y_is_more_than(900),
					    TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);

		DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
		i2c_mechboard_mode_prepare_pickup_next(side, 
						       next_mode);

		strat_set_speed(2000, 2000);
		trajectory_d_rel(&mainboard.traj, -BIG_DIST);
		err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1100),
					    TRAJ_FLAGS_STD);
		if (TRAJ_SUCCESS(err)) /* we should not reach end */
			ERROUT(END_ERROR);
		else if (err)
			ERROUT(err);
		
		DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
		trajectory_d_a_rel(&mainboard.traj, -600, COLOR_A(40));
		err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
		if (!TRAJ_SUCCESS(err))
			ERROUT(err);
			
		DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
		strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
		err = goto_and_avoid_forward(LINE1_X, 
					     COLOR_Y(400),
					     TRAJ_FLAGS_NO_NEAR,
					     TRAJ_FLAGS_NO_NEAR);
		ERROUT(END_TRAJ);
		break;

	default:
		break;
	}
	
	/* should not reach this point */
	ERROUT(END_ERROR);

 end:
	strat_set_speed(old_spdd, old_spda);
	return err;
}
Esempio n. 11
0
static int nand_probe(struct platform_device *pdev)
{
	struct nxp_nand_plat_data *pdata = dev_get_platdata(&pdev->dev);
	struct nxp_nand  *nxp;
	struct mtd_info  *mtd;
	struct nand_chip *chip;
	int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
	int chip_delay = !pdata ? 15 : (pdata->chip_delay ? pdata->chip_delay : 15);
#ifdef CFG_NAND_ECCIRQ_MODE
	int irq = 0; /* platform_get_irq(pdev, 0); */
#endif
	int ret = 0;

	if (pdata == NULL)
		dev_warn(&pdev->dev, "NULL platform data!\n");

	nxp = kzalloc(sizeof (*nxp), GFP_KERNEL);
	if (!nxp) {
		printk(KERN_ERR "NAND: failed to allocate device structure.\n");
		ret = -ENOMEM;
		goto err_kzalloc;
	}

	nxp->pdev = pdev;

	platform_set_drvdata(pdev, nxp);
	mtd = &nxp->mtd;
	chip = &nxp->chip;
	mtd->priv = chip;
	mtd->name = DEV_NAME_NAND;
	mtd->owner = THIS_MODULE;

	nand_dev_init(mtd);

	/* insert callbacks */
	chip->IO_ADDR_R 	= (void __iomem *)__PB_IO_MAP_NAND_VIRT;
	chip->IO_ADDR_W 	= (void __iomem *)__PB_IO_MAP_NAND_VIRT;
	chip->cmd_ctrl 		= nand_cmd_ctrl;
	chip->dev_ready 	= nand_dev_ready;
	chip->select_chip 	= nand_select_chip;
	chip->chip_delay 	= chip_delay;
//	chip->read_buf 		= nand_read_buf;
//	chip->write_buf 	= nand_write_buf;
#if defined (CONFIG_MTD_NAND_ECC_BCH)
//	chip->write_page	= nand_bch_write_page;
#endif

#if defined (CONFIG_MTD_NAND_ECC_HW)
	ret = nand_hw_ecc_init_device(mtd);
	printk(KERN_INFO "NAND ecc: Hardware (delay %d)\n", chip_delay);
#elif defined (CONFIG_MTD_NAND_ECC_BCH)
	chip->ecc.mode 	 = NAND_ECC_SOFT_BCH;

	/* refer to nand_ecc.c */
	switch (ECC_BCH_BITS) {
	case  4: chip->ecc.bytes =   7; chip->ecc.size  =  512; break;
	case  8: chip->ecc.bytes =  13; chip->ecc.size  =  512; break;
	case 12: chip->ecc.bytes =  20; chip->ecc.size  =  512; break;
	case 16: chip->ecc.bytes =  26; chip->ecc.size  =  512; break;
	case 24: chip->ecc.bytes =  42; chip->ecc.size  = 1024; break;
	case 40: chip->ecc.bytes =  70; chip->ecc.size  = 1024; break;
//	case 60: chip->ecc.bytes = 105; chip->ecc.size  = 1024; break;	/* not test */
	default:
		printk("Fail: not supoort bch ecc %d mode !!!\n", ECC_BCH_BITS);
		ret = -1;
		goto err_something;
	}
	printk(KERN_INFO "NAND ecc: Software BCH (delay %d)\n", chip_delay);
#else
	chip->ecc.mode  = NAND_ECC_SOFT;
	printk(KERN_INFO "NAND ecc: Software (delay %d)\n", chip_delay);
#endif

	printk(KERN_NOTICE "Scanning NAND device ...\n");
	if (nand_scan(mtd, maxchips)) {
		ret = -ENXIO;
		goto err_something;
	}

	if (nand_ecc_layout_check(mtd)){
		ret = -ENXIO;
		goto err_something;
	}

#ifdef CFG_NAND_ECCIRQ_MODE
	ret = request_irq(irq, nxp_irq, 0, DEV_NAME_NAND, nxp);
    if (ret < 0) {
        pr_err("%s: failed to request_irq(%d)\n", __func__, 0);
		ret = -ENODEV;
		goto err_something;
    }

	nxp->irq = irq;
#endif

	/* set command partition */
	ret = mtd_device_parse_register(mtd, NULL, 0, pdata->parts, pdata->nr_parts);
	if (ret) {
		nand_release(mtd);
		goto err_something;
	} else {
//		platform_set_drvdata(pdev, chip);
	}

#ifdef CONFIG_NAND_RANDOMIZER
	nxp->pages_per_block_mask = (mtd->erasesize/mtd->writesize) - 1;
	if (!nxp->randomize_buf)
		nxp->randomize_buf = kzalloc(mtd->writesize, GFP_KERNEL);
	if (!nxp->randomize_buf) {
		ERROUT("randomize buffer alloc failed\n");
		goto err_something;
	}
#endif
#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
	if (!nxp->verify_page)
		nxp->verify_page = kzalloc(NAND_MAX_PAGESIZE, GFP_KERNEL);
	if (!nxp->verify_page) {
		ERROUT("verify buffer alloc failed\n");
		goto err_something;
	}
#endif

	nxp_nand_timing_set(mtd);

	printk(KERN_NOTICE "%s: Nand partition \n", ret?"FAIL":"DONE");
	return ret;

err_something:
#ifdef CONFIG_NAND_RANDOMIZER
	if (nxp->randomize_buf)
		kfree (nxp->randomize_buf);
#endif
#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
	if (nxp->verify_page)
		kfree (nxp->verify_page);
#endif
	kfree(nxp);
err_kzalloc:
	return ret;
}
Esempio n. 12
0
static int nand_bch_write_page(struct mtd_info *mtd, struct nand_chip *chip,
			   const uint8_t *buf, int oob_required, int page, int cached, int raw)
{
#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
	int ret = 0;
	struct nxp_nand *nxp = mtd_to_nxp(mtd);
#endif
	int status;

	DBGOUT("%s page %d, raw=%d\n", __func__, page, raw);
	chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);

	/* not verify */
	if (raw)
		chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
	else
		chip->ecc.write_page(mtd, chip, buf, oob_required);

	/*
	 * Cached progamming disabled for now, Not sure if its worth the
	 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s)
	 */
	cached = 0;

	if (!cached || !(chip->options & NAND_CACHEPRG)) {

		chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
		status = chip->waitfunc(mtd, chip);
		/*
		 * See if operation failed and additional status checks are
		 * available
		 */
		if ((status & NAND_STATUS_FAIL) && (chip->errstat))
			status = chip->errstat(mtd, chip, FL_WRITING, status,
					       page);

		if (status & NAND_STATUS_FAIL)
			return -EIO;
	} else {
		chip->cmdfunc(mtd, NAND_CMD_CACHEDPROG, -1, -1);
		status = chip->waitfunc(mtd, chip);
	}

#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
	if (raw)
		return 0;

	/* Send command to read back the data */
	chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
	chip->ecc.read_page(mtd, chip, (uint8_t *)nxp->verify_page, oob_required, page);
	if (ret < 0)
		return -EIO; //		return ret;

	if (memcmp (nxp->verify_page, buf, mtd->writesize))
	{
		ERROUT ("%s fail verify %d page\n", __func__, page);
		return -EIO;
	}

	chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
#endif
	return 0; // mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0
}
Esempio n. 13
0
/*
 * Receive a control message
 */
static int
ng_ksocket_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
	struct thread *td = curthread;	/* XXX broken */
	const priv_p priv = NG_NODE_PRIVATE(node);
	struct socket *const so = priv->so;
	struct ng_mesg *resp = NULL;
	int error = 0;
	struct ng_mesg *msg;
	ng_ID_t raddr;

	NGI_GET_MSG(item, msg);
	switch (msg->header.typecookie) {
	case NGM_KSOCKET_COOKIE:
		switch (msg->header.cmd) {
		case NGM_KSOCKET_BIND:
		    {
			struct sockaddr *const sa
			    = (struct sockaddr *)msg->data;

			/* Sanity check */
			if (msg->header.arglen < SADATA_OFFSET
			    || msg->header.arglen < sa->sa_len)
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Bind */
			error = sobind(so, sa, td);
			break;
		    }
		case NGM_KSOCKET_LISTEN:
		    {
			/* Sanity check */
			if (msg->header.arglen != sizeof(int32_t))
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Listen */
			error = solisten(so, *((int32_t *)msg->data), td);
			break;
		    }

		case NGM_KSOCKET_ACCEPT:
		    {
			/* Sanity check */
			if (msg->header.arglen != 0)
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Make sure the socket is capable of accepting */
			if (!(so->so_options & SO_ACCEPTCONN))
				ERROUT(EINVAL);
			if (priv->flags & KSF_ACCEPTING)
				ERROUT(EALREADY);

			error = ng_ksocket_check_accept(priv);
			if (error != 0 && error != EWOULDBLOCK)
				ERROUT(error);

			/*
			 * If a connection is already complete, take it.
			 * Otherwise let the upcall function deal with
			 * the connection when it comes in.
			 */
			priv->response_token = msg->header.token;
			raddr = priv->response_addr = NGI_RETADDR(item);
			if (error == 0) {
				ng_ksocket_finish_accept(priv);
			} else
				priv->flags |= KSF_ACCEPTING;
			break;
		    }

		case NGM_KSOCKET_CONNECT:
		    {
			struct sockaddr *const sa
			    = (struct sockaddr *)msg->data;

			/* Sanity check */
			if (msg->header.arglen < SADATA_OFFSET
			    || msg->header.arglen < sa->sa_len)
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Do connect */
			if ((so->so_state & SS_ISCONNECTING) != 0)
				ERROUT(EALREADY);
			if ((error = soconnect(so, sa, td)) != 0) {
				soclrstate(so, SS_ISCONNECTING);
				ERROUT(error);
			}
			if ((so->so_state & SS_ISCONNECTING) != 0) {
				/* We will notify the sender when we connect */
				priv->response_token = msg->header.token;
				raddr = priv->response_addr = NGI_RETADDR(item);
				priv->flags |= KSF_CONNECTING;
				ERROUT(EINPROGRESS);
			}
			break;
		    }

		case NGM_KSOCKET_GETNAME:
		case NGM_KSOCKET_GETPEERNAME:
		    {
			int (*func)(struct socket *so, struct sockaddr **nam);
			struct sockaddr *sa = NULL;
			int len;

			/* Sanity check */
			if (msg->header.arglen != 0)
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Get function */
			if (msg->header.cmd == NGM_KSOCKET_GETPEERNAME) {
				if ((so->so_state
				    & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) 
					ERROUT(ENOTCONN);
				func = so->so_proto->pr_usrreqs->pru_peeraddr;
			} else
				func = so->so_proto->pr_usrreqs->pru_sockaddr;

			/* Get local or peer address */
			if ((error = (*func)(so, &sa)) != 0)
				goto bail;
			len = (sa == NULL) ? 0 : sa->sa_len;

			/* Send it back in a response */
			NG_MKRESPONSE(resp, msg, len, M_WAITOK | M_NULLOK);
			if (resp == NULL) {
				error = ENOMEM;
				goto bail;
			}
			bcopy(sa, resp->data, len);

		bail:
			/* Cleanup */
			if (sa != NULL)
				kfree(sa, M_SONAME);
			break;
		    }

		case NGM_KSOCKET_GETOPT:
		    {
			struct ng_ksocket_sockopt *ksopt = 
			    (struct ng_ksocket_sockopt *)msg->data;
			struct sockopt sopt;

			/* Sanity check */
			if (msg->header.arglen != sizeof(*ksopt))
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Get response with room for option value */
			NG_MKRESPONSE(resp, msg, sizeof(*ksopt)
			    + NG_KSOCKET_MAX_OPTLEN, M_WAITOK | M_NULLOK);
			if (resp == NULL)
				ERROUT(ENOMEM);

			/* Get socket option, and put value in the response */
			sopt.sopt_dir = SOPT_GET;
			sopt.sopt_level = ksopt->level;
			sopt.sopt_name = ksopt->name;
			sopt.sopt_td = NULL;
			sopt.sopt_valsize = NG_KSOCKET_MAX_OPTLEN;
			ksopt = (struct ng_ksocket_sockopt *)resp->data;
			sopt.sopt_val = ksopt->value;
			if ((error = sogetopt(so, &sopt)) != 0) {
				NG_FREE_MSG(resp);
				break;
			}

			/* Set actual value length */
			resp->header.arglen = sizeof(*ksopt)
			    + sopt.sopt_valsize;
			break;
		    }

		case NGM_KSOCKET_SETOPT:
		    {
			struct ng_ksocket_sockopt *const ksopt = 
			    (struct ng_ksocket_sockopt *)msg->data;
			const int valsize = msg->header.arglen - sizeof(*ksopt);
			struct sockopt sopt;

			/* Sanity check */
			if (valsize < 0)
				ERROUT(EINVAL);
			if (so == NULL)
				ERROUT(ENXIO);

			/* Set socket option */
			sopt.sopt_dir = SOPT_SET;
			sopt.sopt_level = ksopt->level;
			sopt.sopt_name = ksopt->name;
			sopt.sopt_val = ksopt->value;
			sopt.sopt_valsize = valsize;
			sopt.sopt_td = NULL;
			error = sosetopt(so, &sopt);
			break;
		    }

		default:
			error = EINVAL;
			break;
		}
		break;
	default:
		error = EINVAL;
		break;
	}
done:
	NG_RESPOND_MSG(error, node, item, resp);
	NG_FREE_MSG(msg);
	return (error);
}
Esempio n. 14
0
//===========================================================================
// DIUtilCreateDevice2FromJoyConfig
//
// Helper function to create a DirectInputDevice2 object from a 
//  DirectInputJoyConfig object.
//
// Parameters:
//  short                   nJoystickId     - joystick id for creation
//  HWND                    hWnd            - window handle
//  LPDIRECTINPUT           pdi             - ptr to base DInput object
//  LPDIRECTINPUTJOYCONFIG  pdiJoyCfg       - ptr to joyconfig object
//  LPDIRECTINPUTDEVICE     *ppdiDevice2    - ptr to device object ptr
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilCreateDevice2FromJoyConfig(short nJoystickId, HWND hWnd,
                            LPDIRECTINPUT pdi,
                            LPDIRECTINPUTJOYCONFIG pdiJoyCfg,
                            LPDIRECTINPUTDEVICE2 *ppdiDevice2)
{
    HRESULT                 hRes        = E_NOTIMPL;
    LPDIRECTINPUTDEVICE     pdiDevTemp  = NULL;
    DIJOYCONFIG             dijc;
    
    // validate pointers
    if( (IsBadReadPtr((void*)pdi, sizeof(IDirectInput))) ||
        (IsBadWritePtr((void*)pdi, sizeof(IDirectInput))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid pdi\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) ||
        (IsBadWritePtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid pdiJoyCfg\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)ppdiDevice2, sizeof(LPDIRECTINPUTDEVICE2))) ||
        (IsBadWritePtr((void*)ppdiDevice2, sizeof(LPDIRECTINPUTDEVICE2))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid ppdiDevice2\n"));
        return E_POINTER;
    }

    // get the instance GUID for device configured as nJoystickId
    // 
    // GetConfig will provide this information
    dijc.dwSize = sizeof(DIJOYCONFIG);
    hRes = pdiJoyCfg->GetConfig(nJoystickId, &dijc, DIJC_GUIDINSTANCE);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - GetConfig() failed\n"));
        return hRes;
    }

    // create temporary device object
    //
    // use the instance GUID returned by GetConfig()
    hRes = pdi->CreateDevice(dijc.guidInstance, &pdiDevTemp, NULL);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - CreateDevice() failed\n"));
        return hRes;
    }

    // query for a device2 object
    hRes = pdiDevTemp->QueryInterface(IID_IDirectInputDevice2, (LPVOID*)ppdiDevice2);
    
    // release the temporary object
    pdiDevTemp->Release();

    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - QueryInterface(IDirectInputDevice2) failed\n"));
        return hRes;
    }

    // set the desired data format
    //
    // we want to be a joystick
    hRes = (*ppdiDevice2)->SetDataFormat(&c_dfDIJoystick);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - SetDataFormat(Joystick) failed\n"));
        return hRes;
    }
    
    // set the cooperative level for the device
    //
    // want to set EXCLUSIVE | BACKGROUND
    hRes = (*ppdiDevice2)->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - SetCooperativeLevel() failed\n"));
        return hRes;
    }

    // all is well
    return hRes;

} //*** end DIUtilCreateDevice2FromJoyConfig()
Esempio n. 15
0
static int
puffs_vnop_readdir(struct vop_readdir_args *ap)
{
    PUFFS_MSG_VARS(vn, readdir);
    struct vnode *vp = ap->a_vp;
    struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
    size_t argsize, tomove, cookiemem, cookiesmax;
    struct uio *uio = ap->a_uio;
    size_t howmuch, resid;
    int error;

    if (!EXISTSOP(pmp, READDIR))
        return EOPNOTSUPP;

    /*
     * ok, so we need: resid + cookiemem = maxreq
     * => resid + cookiesize * (resid/minsize) = maxreq
     * => resid + cookiesize/minsize * resid = maxreq
     * => (cookiesize/minsize + 1) * resid = maxreq
     * => resid = maxreq / (cookiesize/minsize + 1)
     *
     * Since cookiesize <= minsize and we're not very big on floats,
     * we approximate that to be 1.  Therefore:
     *
     * resid = maxreq / 2;
     *
     * Well, at least we didn't have to use differential equations
     * or the Gram-Schmidt process.
     *
     * (yes, I'm very afraid of this)
     */
    KKASSERT(CSIZE <= _DIRENT_RECLEN(1));

    if (ap->a_cookies) {
        KKASSERT(ap->a_ncookies != NULL);
        if (pmp->pmp_args.pa_fhsize == 0)
            return EOPNOTSUPP;
        resid = PUFFS_TOMOVE(uio->uio_resid, pmp) / 2;
        cookiesmax = resid/_DIRENT_RECLEN(1);
        cookiemem = ALIGN(cookiesmax*CSIZE); /* play safe */
    } else {
        resid = PUFFS_TOMOVE(uio->uio_resid, pmp);
        cookiesmax = 0;
        cookiemem = 0;
    }

    argsize = sizeof(struct puffs_vnmsg_readdir);
    tomove = resid + cookiemem;
    puffs_msgmem_alloc(argsize + tomove, &park_readdir,
                       (void *)&readdir_msg, 1);

    puffs_credcvt(&readdir_msg->pvnr_cred, ap->a_cred);
    readdir_msg->pvnr_offset = uio->uio_offset;
    readdir_msg->pvnr_resid = resid;
    readdir_msg->pvnr_ncookies = cookiesmax;
    readdir_msg->pvnr_eofflag = 0;
    readdir_msg->pvnr_dentoff = cookiemem;
    puffs_msg_setinfo(park_readdir, PUFFSOP_VN,
                      PUFFS_VN_READDIR, VPTOPNC(vp));
    puffs_msg_setdelta(park_readdir, tomove);

    PUFFS_MSG_ENQUEUEWAIT2(pmp, park_readdir, vp->v_data, NULL, error);
    error = checkerr(pmp, error, __func__);
    if (error)
        goto out;

    /* userspace is cheating? */
    if (readdir_msg->pvnr_resid > resid) {
        puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
                      "resid grew", VPTOPNC(vp));
        ERROUT(EPROTO);
    }
    if (readdir_msg->pvnr_ncookies > cookiesmax) {
        puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
                      "too many cookies", VPTOPNC(vp));
        ERROUT(EPROTO);
    }

    /* check eof */
    if (readdir_msg->pvnr_eofflag)
        *ap->a_eofflag = 1;

    /* bouncy-wouncy with the directory data */
    howmuch = resid - readdir_msg->pvnr_resid;

    /* force eof if no data was returned (getcwd() needs this) */
    if (howmuch == 0) {
        *ap->a_eofflag = 1;
        goto out;
    }

    error = uiomove(readdir_msg->pvnr_data + cookiemem, howmuch, uio);
    if (error)
        goto out;

    /* provide cookies to caller if so desired */
    if (ap->a_cookies) {
        *ap->a_cookies = kmalloc(readdir_msg->pvnr_ncookies*CSIZE,
                                 M_TEMP, M_WAITOK);
        *ap->a_ncookies = readdir_msg->pvnr_ncookies;
        memcpy(*ap->a_cookies, readdir_msg->pvnr_data,
               *ap->a_ncookies*CSIZE);
    }

    /* next readdir starts here */
    uio->uio_offset = readdir_msg->pvnr_offset;

out:
    puffs_msgmem_release(park_readdir);
    return error;
}
Esempio n. 16
0
/*
 * Receive a control message
 */
static int
ng_vjc_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
	const priv_p priv = NG_NODE_PRIVATE(node);
	struct ng_mesg *resp = NULL;
	int error = 0;
	struct ng_mesg *msg;

	NGI_GET_MSG(item, msg);
	/* Check type cookie */
	switch (msg->header.typecookie) {
	case NGM_VJC_COOKIE:
		switch (msg->header.cmd) {
		case NGM_VJC_SET_CONFIG:
		    {
			struct ngm_vjc_config *const c =
				(struct ngm_vjc_config *) msg->data;

			if (msg->header.arglen != sizeof(*c))
				ERROUT(EINVAL);
			if ((priv->conf.enableComp || priv->conf.enableDecomp)
			    && (c->enableComp || c->enableDecomp))
				ERROUT(EALREADY);
			if (c->enableComp) {
				if (c->maxChannel > NG_VJC_MAX_CHANNELS - 1
				    || c->maxChannel < NG_VJC_MIN_CHANNELS - 1)
					ERROUT(EINVAL);
			} else
				c->maxChannel = NG_VJC_MAX_CHANNELS - 1;
			if (c->enableComp != 0 || c->enableDecomp != 0) {
				bzero(&priv->slc, sizeof(priv->slc));
				sl_compress_init(&priv->slc, c->maxChannel);
			}
			priv->conf = *c;
			break;
		    }
		case NGM_VJC_GET_CONFIG:
		    {
			struct ngm_vjc_config *conf;

			NG_MKRESPONSE(resp, msg, sizeof(*conf), M_NOWAIT);
			if (resp == NULL)
				ERROUT(ENOMEM);
			conf = (struct ngm_vjc_config *)resp->data;
			*conf = priv->conf;
			break;
		    }
		case NGM_VJC_GET_STATE:
		    {
			const struct slcompress *const sl0 = &priv->slc;
			struct slcompress *sl;
			u_int16_t index;
			int i;

			/* Get response structure */
			NG_MKRESPONSE(resp, msg, sizeof(*sl), M_NOWAIT);
			if (resp == NULL)
				ERROUT(ENOMEM);
			sl = (struct slcompress *)resp->data;
			*sl = *sl0;

			/* Replace pointers with integer indicies */
			if (sl->last_cs != NULL) {
				index = sl0->last_cs - sl0->tstate;
				bzero(&sl->last_cs, sizeof(sl->last_cs));
				*((u_int16_t *)&sl->last_cs) = index;
			}
			for (i = 0; i < MAX_STATES; i++) {
				struct cstate *const cs = &sl->tstate[i];

				index = sl0->tstate[i].cs_next - sl0->tstate;
				bzero(&cs->cs_next, sizeof(cs->cs_next));
				*((u_int16_t *)&cs->cs_next) = index;
			}
			break;
		    }
		case NGM_VJC_CLR_STATS:
			priv->slc.sls_packets = 0;
			priv->slc.sls_compressed = 0;
			priv->slc.sls_searches = 0;
			priv->slc.sls_misses = 0;
			priv->slc.sls_uncompressedin = 0;
			priv->slc.sls_compressedin = 0;
			priv->slc.sls_errorin = 0;
			priv->slc.sls_tossed = 0;
			break;
		case NGM_VJC_RECV_ERROR:
			sl_uncompress_tcp(NULL, 0, TYPE_ERROR, &priv->slc);
			break;
		default:
			error = EINVAL;
			break;
		}
		break;
	default:
		error = EINVAL;
		break;
	}
done:
	NG_RESPOND_MSG(error, node, item, resp);
	NG_FREE_MSG(msg);
	return (error);
}