status_t PackageSettings::Load(dev_t mountPointDeviceID, ino_t mountPointNodeID, PackageFSMountType mountType) { status_t error = fPackageItems.Init(); if (error != B_OK) RETURN_ERROR(error); // get the mount point relative settings file path const char* settingsFilePath = mountType == PACKAGE_FS_MOUNT_TYPE_HOME ? kUserSettingsGlobalDirectory "/packages" + strlen(kUserConfigDirectory) + 1 : kSystemSettingsDirectory "/packages" + strlen(kSystemDirectory) + 1; // get an absolute path KPath path; if (path.InitCheck() != B_OK) RETURN_ERROR(path.InitCheck()); error = vfs_entry_ref_to_path(mountPointDeviceID, mountPointNodeID, NULL, true, path.LockBuffer(), path.BufferSize()); if (error != B_OK) return error; path.UnlockBuffer(); error = path.Append(settingsFilePath); if (error != B_OK) return error; // load the driver settings void* settingsHandle = load_driver_settings(path.Path()); if (settingsHandle == NULL) return B_ENTRY_NOT_FOUND; CObjectDeleter<void, status_t> settingsDeleter(settingsHandle, &unload_driver_settings); const driver_settings* settings = get_driver_settings(settingsHandle); for (int i = 0; i < settings->parameter_count; i++) { const driver_parameter& parameter = settings->parameters[i]; if (strcmp(parameter.name, "Package") != 0 || parameter.value_count < 1) { continue; } error = _AddPackageSettingsItem(parameter); // abort only in case of serious issues (memory shortage) if (error == B_NO_MEMORY) return error; } return B_OK; }
status_t PackagesDirectory::_Init(struct vnode* vnode, struct stat& _st) { fDirFD = vfs_open_vnode(vnode, O_RDONLY, true); if (fDirFD < 0) { ERROR("Failed to open packages directory \"%s\"\n", strerror(fDirFD)); vfs_put_vnode(vnode); RETURN_ERROR(fDirFD); } // Our vnode reference has been transferred to the FD. // Is it a directory at all? struct stat& st = _st; if (fstat(fDirFD, &st) < 0) RETURN_ERROR(errno); fNodeRef.device = st.st_dev; fNodeRef.node = st.st_ino; // get a normalized path KPath normalizedPath; if (normalizedPath.InitCheck() != B_OK) RETURN_ERROR(normalizedPath.InitCheck()); char* normalizedPathBuffer = normalizedPath.LockBuffer(); status_t error = vfs_entry_ref_to_path(fNodeRef.device, fNodeRef.node, NULL, true, normalizedPathBuffer, normalizedPath.BufferSize()); if (error != B_OK) RETURN_ERROR(error); fPath = strdup(normalizedPathBuffer); if (fPath == NULL) RETURN_ERROR(B_NO_MEMORY); return B_OK; }
// 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; }