Ejemplo n.º 1
0
status_t
AddOnManager::_RegisterAddOn(BEntry& entry)
{
	BPath path(&entry);

	entry_ref ref;
	status_t status = entry.GetRef(&ref);
	if (status < B_OK)
		return status;

	TRACE("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n",
		path.Path());

	image_id image = load_add_on(path.Path());
	if (image < B_OK) {
		ERROR("load addon %s failed\n", path.Path());
		return image;
	}

	status = B_ERROR;

	if (_IsDevice(path.Path())) {
		BInputServerDevice* device = instantiate_add_on<BInputServerDevice>(
			image, path.Path(), "device");
		if (device != NULL)
			status = _RegisterDevice(device, ref, image);
	} else if (_IsFilter(path.Path())) {
		BInputServerFilter* filter = instantiate_add_on<BInputServerFilter>(
			image, path.Path(), "filter");
		if (filter != NULL)
			status = _RegisterFilter(filter, ref, image);
	} else if (_IsMethod(path.Path())) {
		BInputServerMethod* method = instantiate_add_on<BInputServerMethod>(
			image, path.Path(), "method");
		if (method != NULL)
			status = _RegisterMethod(method, ref, image);
	} else {
		ERROR("AddOnManager::_RegisterAddOn(): addon type not found for "
			"\"%s\" \n", path.Path());
	}

	if (status != B_OK)
		unload_add_on(image);

	return status;
}
Ejemplo n.º 2
0
// SetTo
status_t
KFileDiskDevice::SetTo(const char *filePath, const char *devicePath)
{
    // check params
    if (!filePath || strlen(filePath) > B_PATH_NAME_LENGTH
            || (devicePath && strlen(devicePath) > B_PATH_NAME_LENGTH)) {
        return B_BAD_VALUE;
    }
    // normalize the file path
    // (should actually not be necessary, since this method is only invoked
    // by the DDM, which has already normalized the path)
    KPath tmpFilePath;
    status_t error = tmpFilePath.SetTo(filePath, true);
    if (error != B_OK)
        return error;
    // check the file
    struct stat st;
    if (stat(filePath, &st) != 0)
        return errno;
    if (!S_ISREG(st.st_mode))
        return B_BAD_VALUE;
    // create the device, if requested
    KPath tmpDevicePath;
    if (!devicePath) {
        // no device path: we shall create a new device entry
        if (tmpDevicePath.InitCheck() != B_OK)
            return tmpDevicePath.InitCheck();
// TODO: Cleanup. The directory creation is done automatically by the devfs.
//		// make the file devices dir
//		if (mkdir(kFileDevicesDir, 0777) != 0) {
//			if (errno != B_FILE_EXISTS)
//				return errno;
//		}
        // make the directory
        status_t error = _GetDirectoryPath(ID(), &tmpDevicePath);
        if (error != B_OK)
            return error;
//		if (mkdir(tmpDevicePath.Path(), 0777) != 0)
//			return errno;
        // get the device path name
        error = tmpDevicePath.Append("raw");
        if (error != B_OK)
            return error;
        devicePath = tmpDevicePath.Path();
        // register the file as virtual disk device
        error = _RegisterDevice(filePath, devicePath);
        if (error != B_OK)
            return error;
    }
    error = set_string(fFilePath, filePath);
    if (error != B_OK)
        return error;

    error = KDiskDevice::SetTo(devicePath);
    if (error != B_OK)
        return error;

    // reset the B_DISK_DEVICE_IS_FILE flag -- KDiskDevice::SetTo() has cleared
    // it
    SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_IS_FILE);

    return B_OK;
}