Node::fRefCount is now 1 after creation, so that a following Acquire()/Release()
pair doesn't delete the object anymore (creation is regarded as an Acquire() equivalent now). Moved mount_boot_partitions() and vfs_init(). Debug output can be turned off now. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4631 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -16,6 +16,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
using namespace boot;
|
||||||
|
|
||||||
|
#define TRACE_VFS 0
|
||||||
|
#if TRACE_VFS
|
||||||
|
# define TRACE(x) printf x
|
||||||
|
#else
|
||||||
|
# define TRACE(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class Descriptor {
|
class Descriptor {
|
||||||
public:
|
public:
|
||||||
@@ -52,7 +61,7 @@ Directory *gRoot;
|
|||||||
|
|
||||||
Node::Node()
|
Node::Node()
|
||||||
:
|
:
|
||||||
fRefCount(0)
|
fRefCount(1)
|
||||||
{
|
{
|
||||||
fLink.next = fLink.prev = NULL;
|
fLink.next = fLink.prev = NULL;
|
||||||
}
|
}
|
||||||
@@ -108,8 +117,11 @@ Node::Acquire()
|
|||||||
status_t
|
status_t
|
||||||
Node::Release()
|
Node::Release()
|
||||||
{
|
{
|
||||||
if (--fRefCount == 0)
|
if (--fRefCount == 0) {
|
||||||
|
TRACE(("delete node: %p\n", this));
|
||||||
delete this;
|
delete this;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -264,6 +276,70 @@ Descriptor::Release()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
vfs_init(stage2_args *args)
|
||||||
|
{
|
||||||
|
list_init(&gBootDevices);
|
||||||
|
list_init(&gPartitions);
|
||||||
|
|
||||||
|
status_t status = platform_get_boot_devices(args, &gBootDevices);
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
mount_boot_file_systems()
|
||||||
|
{
|
||||||
|
list_init_etc(&gPartitions, Partition::LinkOffset());
|
||||||
|
|
||||||
|
gRoot = new RootFileSystem();
|
||||||
|
if (gRoot == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
Node *device = NULL, *last = NULL;
|
||||||
|
while ((device = (Node *)list_get_next_item(&gBootDevices, device)) != NULL) {
|
||||||
|
int fd = open_node(device, O_RDONLY);
|
||||||
|
if (fd < B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//#if TRACE_VFS
|
||||||
|
char name[B_FILE_NAME_LENGTH];
|
||||||
|
if (device->GetName(name, sizeof(name)) == B_OK)
|
||||||
|
printf("add partitions for \"%s\"\n", name);
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
status_t status = add_partitions_for(fd);
|
||||||
|
if (status < B_OK)
|
||||||
|
printf("add_partitions_for(%d) failed: %s\n", fd, strerror(status));
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
// ToDo: we can't delete the object here, because it must
|
||||||
|
// be removed from the list before we know that it was
|
||||||
|
// deleted.
|
||||||
|
|
||||||
|
/* // if the Release() deletes the object, we need to skip it
|
||||||
|
if (device->Release() > 0) {
|
||||||
|
list_remove_item(&gBootDevices, device);
|
||||||
|
device = last;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
last = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list_is_empty(&gPartitions))
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
static Descriptor *
|
static Descriptor *
|
||||||
get_descriptor(int fd)
|
get_descriptor(int fd)
|
||||||
{
|
{
|
||||||
@@ -305,7 +381,7 @@ open_node(Node *node, int mode)
|
|||||||
if (fd == MAX_VFS_DESCRIPTORS)
|
if (fd == MAX_VFS_DESCRIPTORS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
printf("got descriptor %d\n", fd);
|
TRACE(("got descriptor %d\n", fd));
|
||||||
|
|
||||||
// we got a free descriptor entry, now try to open the node
|
// we got a free descriptor entry, now try to open the node
|
||||||
|
|
||||||
@@ -314,7 +390,7 @@ open_node(Node *node, int mode)
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
printf("could open node at %p\n", node);
|
TRACE(("could open node at %p\n", node));
|
||||||
|
|
||||||
Descriptor *descriptor = new Descriptor(node, cookie);
|
Descriptor *descriptor = new Descriptor(node, cookie);
|
||||||
if (descriptor == NULL)
|
if (descriptor == NULL)
|
||||||
@@ -326,48 +402,6 @@ open_node(Node *node, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
vfs_init(stage2_args *args)
|
|
||||||
{
|
|
||||||
list_init(&gBootDevices);
|
|
||||||
list_init(&gPartitions);
|
|
||||||
|
|
||||||
status_t status = platform_get_boot_devices(args, &gBootDevices);
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
mount_boot_file_systems()
|
|
||||||
{
|
|
||||||
list_init_etc(&gPartitions, Partition::LinkOffset());
|
|
||||||
|
|
||||||
gRoot = new RootFileSystem();
|
|
||||||
if (gRoot == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
Node *device = NULL;
|
|
||||||
while ((device = (Node *)list_get_next_item(&gBootDevices, (void *)device)) != NULL) {
|
|
||||||
int fd = open_node(device, O_RDONLY);
|
|
||||||
if (fd < B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
puts("add partitions");
|
|
||||||
add_partitions_for(fd);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list_is_empty(&gPartitions))
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void *
|
void *
|
||||||
mount(void *from, const char *name)
|
mount(void *from, const char *name)
|
||||||
|
|||||||
Reference in New Issue
Block a user