* Added mapping of dup() in the FS shell.
* Adjusted the FS initialize() hook to have FD and partition_id parameters like the other hooks instead of the partition path. * Adjusted initialization in BFS accordingly. * Implemented the FS initialization method in KFileSystem. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21788 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -245,10 +245,8 @@ typedef struct file_system_module_info {
|
|||||||
const char *name, disk_job_id job);
|
const char *name, disk_job_id job);
|
||||||
status_t (*set_content_parameters)(int fd, partition_id partition,
|
status_t (*set_content_parameters)(int fd, partition_id partition,
|
||||||
const char *parameters, disk_job_id job);
|
const char *parameters, disk_job_id job);
|
||||||
status_t (*initialize)(const char *partition, const char *name,
|
status_t (*initialize)(int fd, partition_id partition, const char *name,
|
||||||
const char *parameters, disk_job_id job);
|
const char *parameters, disk_job_id job);
|
||||||
// This is pretty close to how the hook in R5 looked. Save the job ID,
|
|
||||||
// of course and that the parameters were given as (void*, size_t) pair.
|
|
||||||
} file_system_module_info;
|
} file_system_module_info;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -279,10 +279,8 @@ typedef struct fssh_file_system_module_info {
|
|||||||
const char *name, fssh_disk_job_id job);
|
const char *name, fssh_disk_job_id job);
|
||||||
fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition,
|
fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition,
|
||||||
const char *parameters, fssh_disk_job_id job);
|
const char *parameters, fssh_disk_job_id job);
|
||||||
fssh_status_t (*initialize)(const char *partition, const char *name,
|
fssh_status_t (*initialize)(int fd, fssh_partition_id partition,
|
||||||
const char *parameters, fssh_disk_job_id job);
|
const char *name, const char *parameters, fssh_disk_job_id job);
|
||||||
// This is pretty close to how the hook in R5 looked. Save the job ID,
|
|
||||||
// of course and that the parameters were given as (void*, size_t) pair.
|
|
||||||
} fssh_file_system_module_info;
|
} fssh_file_system_module_info;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,12 @@ static const int32 kDesiredAllocationGroups = 56;
|
|||||||
|
|
||||||
class DeviceOpener {
|
class DeviceOpener {
|
||||||
public:
|
public:
|
||||||
|
DeviceOpener(int fd, int mode);
|
||||||
DeviceOpener(const char *device, int mode);
|
DeviceOpener(const char *device, int mode);
|
||||||
~DeviceOpener();
|
~DeviceOpener();
|
||||||
|
|
||||||
int Open(const char *device, int mode);
|
int Open(const char *device, int mode);
|
||||||
|
int Open(int fd, int mode);
|
||||||
void *InitCache(off_t numBlocks, uint32 blockSize);
|
void *InitCache(off_t numBlocks, uint32 blockSize);
|
||||||
void RemoveCache(bool allowWrites);
|
void RemoveCache(bool allowWrites);
|
||||||
|
|
||||||
@@ -56,6 +58,14 @@ DeviceOpener::DeviceOpener(const char *device, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DeviceOpener::DeviceOpener(int fd, int mode)
|
||||||
|
:
|
||||||
|
fBlockCache(NULL)
|
||||||
|
{
|
||||||
|
Open(fd, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceOpener::~DeviceOpener()
|
DeviceOpener::~DeviceOpener()
|
||||||
{
|
{
|
||||||
if (fDevice >= B_OK) {
|
if (fDevice >= B_OK) {
|
||||||
@@ -97,6 +107,19 @@ DeviceOpener::Open(const char *device, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
DeviceOpener::Open(int fd, int mode)
|
||||||
|
{
|
||||||
|
fDevice = dup(fd);
|
||||||
|
if (fDevice < 0)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
fMode = mode;
|
||||||
|
|
||||||
|
return fDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize)
|
DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize)
|
||||||
{
|
{
|
||||||
@@ -563,7 +586,7 @@ Volume::Identify(int fd, disk_super_block *superBlock)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Volume::Initialize(const char *device, const char *name, uint32 blockSize,
|
Volume::Initialize(int fd, const char *name, uint32 blockSize,
|
||||||
uint32 flags)
|
uint32 flags)
|
||||||
{
|
{
|
||||||
// although there is no really good reason for it, we won't
|
// although there is no really good reason for it, we won't
|
||||||
@@ -576,7 +599,7 @@ Volume::Initialize(const char *device, const char *name, uint32 blockSize,
|
|||||||
&& blockSize != 8192)
|
&& blockSize != 8192)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
DeviceOpener opener(device, O_RDWR);
|
DeviceOpener opener(fd, O_RDWR);
|
||||||
if (opener.Device() < B_OK)
|
if (opener.Device() < B_OK)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class Volume {
|
|||||||
|
|
||||||
status_t Mount(const char *device, uint32 flags);
|
status_t Mount(const char *device, uint32 flags);
|
||||||
status_t Unmount();
|
status_t Unmount();
|
||||||
status_t Initialize(const char *device, const char *name,
|
status_t Initialize(int fd, const char *name,
|
||||||
uint32 blockSize, uint32 flags);
|
uint32 blockSize, uint32 flags);
|
||||||
|
|
||||||
bool IsValidSuperBlock();
|
bool IsValidSuperBlock();
|
||||||
|
|||||||
@@ -2038,12 +2038,9 @@ bfs_validate_initialize(partition_data *partition, char *name,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
bfs_initialize(const char *partition, const char *name, const char *parameters,
|
bfs_initialize(int fd, partition_id partition, const char *name,
|
||||||
disk_job_id job)
|
const char *parameters, disk_job_id job)
|
||||||
{
|
{
|
||||||
if (partition == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
uint32 blockSize = 1024;
|
uint32 blockSize = 1024;
|
||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
@@ -2070,7 +2067,7 @@ bfs_initialize(const char *partition, const char *name, const char *parameters,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Volume volume(-1);
|
Volume volume(-1);
|
||||||
status_t status = volume.Initialize(partition, name, blockSize, flags);
|
status_t status = volume.Initialize(fd, name, blockSize, flags);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
INFORM(("Initializing volume failed: %s\n", strerror(status)));
|
INFORM(("Initializing volume failed: %s\n", strerror(status)));
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ BDiskDevice::CommitModifications(bool synchronously,
|
|||||||
if (!_IsShadow())
|
if (!_IsShadow())
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
// TODO: Get port and token from the progressMessenger
|
// TODO: Get port and token from the progressMessenger
|
||||||
|
// TODO: Respect "synchronously"!
|
||||||
port_id port = -1;
|
port_id port = -1;
|
||||||
int32 token = -1;
|
int32 token = -1;
|
||||||
error = _kern_commit_disk_device_modifications(ID(), port, token,
|
error = _kern_commit_disk_device_modifications(ID(), port, token,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <fs_interface.h>
|
#include <fs_interface.h>
|
||||||
|
|
||||||
#include "ddm_modules.h"
|
#include "ddm_modules.h"
|
||||||
|
#include "KDiskDeviceJob.h"
|
||||||
#include "KDiskDeviceUtils.h"
|
#include "KDiskDeviceUtils.h"
|
||||||
#include "KFileSystem.h"
|
#include "KFileSystem.h"
|
||||||
#include "KPartition.h"
|
#include "KPartition.h"
|
||||||
@@ -308,8 +309,31 @@ status_t
|
|||||||
KFileSystem::Initialize(KPartition *partition, const char *name,
|
KFileSystem::Initialize(KPartition *partition, const char *name,
|
||||||
const char *parameters, KDiskDeviceJob *job)
|
const char *parameters, KDiskDeviceJob *job)
|
||||||
{
|
{
|
||||||
// to be implemented
|
// check parameters
|
||||||
return B_ERROR;
|
if (!partition || !job || !fModule)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
if (!fModule->initialize)
|
||||||
|
return B_NOT_SUPPORTED;
|
||||||
|
|
||||||
|
// open partition device (we need a temporary read-lock)
|
||||||
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
|
if (!manager->ReadLockPartition(partition->ID()))
|
||||||
|
return B_ERROR;
|
||||||
|
DeviceReadLocker locker(partition->Device(), true);
|
||||||
|
|
||||||
|
int fd = -1;
|
||||||
|
status_t result = partition->Open(O_RDWR, &fd);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
locker.Unlock();
|
||||||
|
|
||||||
|
// call the module hook
|
||||||
|
result = fModule->initialize(fd, partition->ID(), name, parameters,
|
||||||
|
job->ID());
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -901,6 +901,7 @@ KPartitioningSystem::Initialize(KPartition *partition, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// let the module do its job
|
// let the module do its job
|
||||||
|
// TODO: The partition must not be locked at this point!
|
||||||
status_t result = fModule->initialize(fd, partition->ID(), name, parameters,
|
status_t result = fModule->initialize(fd, partition->ID(), name, parameters,
|
||||||
job->ID());
|
job->ID());
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef __BEOS__
|
#ifndef __BEOS__
|
||||||
// The _kern_close() defined in libroot_build.so.
|
// Defined in libroot_build.so.
|
||||||
|
extern "C" int _kern_dup(int fd);
|
||||||
extern "C" status_t _kern_close(int fd);
|
extern "C" status_t _kern_close(int fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -76,6 +77,24 @@ get_partition_size(int fd, off_t maxSize)
|
|||||||
#endif // HAIKU_HOST_PLATFORM_LINUX
|
#endif // HAIKU_HOST_PLATFORM_LINUX
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
fssh_dup(int fd)
|
||||||
|
{
|
||||||
|
// Use the _kern_dup() defined in libroot on BeOS incompatible systems.
|
||||||
|
// Required for proper attribute emulation support.
|
||||||
|
#if __BEOS__
|
||||||
|
return dup(fd);
|
||||||
|
#else
|
||||||
|
int result = _kern_dup(fd);
|
||||||
|
if (result < 0) {
|
||||||
|
fssh_set_errno(result);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fssh_close(int fd)
|
fssh_close(int fd)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-15
@@ -16,6 +16,7 @@
|
|||||||
#include "fssh_atomic.h"
|
#include "fssh_atomic.h"
|
||||||
#include "fssh_defs.h"
|
#include "fssh_defs.h"
|
||||||
#include "fssh_dirent.h"
|
#include "fssh_dirent.h"
|
||||||
|
#include "fssh_errno.h"
|
||||||
#include "fssh_fcntl.h"
|
#include "fssh_fcntl.h"
|
||||||
#include "fssh_fs_info.h"
|
#include "fssh_fs_info.h"
|
||||||
#include "fssh_fs_volume.h"
|
#include "fssh_fs_volume.h"
|
||||||
@@ -5184,30 +5185,30 @@ _kern_initialize_volume(const char* fsName, const char *partition,
|
|||||||
|
|
||||||
// The partition argument should point to a real file/device.
|
// The partition argument should point to a real file/device.
|
||||||
|
|
||||||
// normalize the device path
|
// open partition
|
||||||
KPath normalizedDevice;
|
int fd = fssh_open(partition, FSSH_O_RDWR);
|
||||||
// status = normalizedDevice.SetTo(device, true);
|
if (fd < 0)
|
||||||
// NOTE: normalizing works only in our namespace.
|
return fssh_errno;
|
||||||
fssh_status_t status = normalizedDevice.SetTo(partition, false);
|
|
||||||
if (status != FSSH_B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
partition = normalizedDevice.Path();
|
|
||||||
// correct path to file device
|
|
||||||
|
|
||||||
// get the file system module
|
// get the file system module
|
||||||
fssh_file_system_module_info* fsModule = get_file_system(fsName);
|
fssh_file_system_module_info* fsModule = get_file_system(fsName);
|
||||||
if (fsModule == NULL)
|
if (fsModule == NULL) {
|
||||||
|
fssh_close(fd);
|
||||||
return FSSH_ENODEV;
|
return FSSH_ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
// initialize
|
// initialize
|
||||||
if (fsModule->initialize)
|
fssh_status_t status;
|
||||||
status = (*fsModule->initialize)(partition, name, parameters, -1);
|
if (fsModule->initialize) {
|
||||||
else
|
status = (*fsModule->initialize)(fd, -1, name, parameters, -1);
|
||||||
|
// We've got no partition or job IDs -- the FS will hopefully
|
||||||
|
// ignore that.
|
||||||
|
} else
|
||||||
status = FSSH_B_NOT_SUPPORTED;
|
status = FSSH_B_NOT_SUPPORTED;
|
||||||
|
|
||||||
// put the file system module
|
// put the file system module, close partition
|
||||||
put_file_system(fsModule);
|
put_file_system(fsModule);
|
||||||
|
fssh_close(fd);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user