Skip to content

Commit

Permalink
Boot loader: Add get_stat(), directory_from()
Browse files Browse the repository at this point in the history
* Add Node::Stat() and simplify Descriptor::Stat().
* Add get_stat() and directory_from().
  • Loading branch information
weinhold committed Apr 18, 2014
1 parent 2f019bd commit 59ae1c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
10 changes: 9 additions & 1 deletion headers/private/kernel/boot/vfs.h
Expand Up @@ -17,6 +17,7 @@
#ifdef __cplusplus

struct file_map_run;
struct stat;

/** This is the base class for all VFS nodes */

Expand All @@ -41,6 +42,8 @@ class Node : public DoublyLinkedListLinkImpl<Node> {
virtual off_t Size() const;
virtual ino_t Inode() const;

void Stat(struct stat& stat);

status_t Acquire();
status_t Release();

Expand Down Expand Up @@ -149,8 +152,13 @@ extern int open_node(Node *node, int mode);
extern int open_from(Directory *directory, const char *path, int mode,
mode_t permissions = 0);
extern DIR* open_directory(Directory* baseDirectory, const char* path);
extern status_t get_stat(Directory* directory, const char* path,
struct stat& st);

extern Node *get_node_from(int fd);
extern Node* get_node_from(int fd);
// returns a reference
extern Directory* directory_from(DIR* dir);
// does not return a reference

extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
Expand Down
43 changes: 35 additions & 8 deletions src/system/boot/loader/vfs.cpp
Expand Up @@ -55,7 +55,7 @@ class Descriptor {
ssize_t WriteAt(off_t pos, const void *buffer, size_t bufferSize);
ssize_t Write(const void *buffer, size_t bufferSize);

status_t Stat(struct stat &stat);
void Stat(struct stat &stat);

off_t Offset() const { return fOffset; }
int32 RefCount() const { return fRefCount; }
Expand Down Expand Up @@ -151,6 +151,15 @@ Node::Inode() const
}


void
Node::Stat(struct stat& stat)
{
stat.st_mode = Type();
stat.st_size = Size();
stat.st_ino = Inode();
}


status_t
Node::Acquire()
{
Expand Down Expand Up @@ -374,14 +383,10 @@ Descriptor::WriteAt(off_t pos, const void *buffer, size_t bufferSize)
}


status_t
void
Descriptor::Stat(struct stat &stat)
{
stat.st_mode = fNode->Type();
stat.st_size = fNode->Size();
stat.st_ino = fNode->Inode();

return B_OK;
fNode->Stat(stat);
}


Expand Down Expand Up @@ -999,6 +1004,27 @@ get_node_from(int fd)
}


status_t
get_stat(Directory* directory, const char* path, struct stat& st)
{
Node* node;
status_t error = get_node_for_path(directory, path, &node);
if (error != B_OK)
return error;

node->Stat(st);
node->Release();
return B_OK;
}


Directory*
directory_from(DIR* dir)
{
return dir != NULL ? dir->directory : NULL;
}


int
close(int fd)
{
Expand Down Expand Up @@ -1029,7 +1055,8 @@ fstat(int fd, struct stat *stat)
if (descriptor == NULL)
RETURN_AND_SET_ERRNO(B_FILE_ERROR);

RETURN_AND_SET_ERRNO(descriptor->Stat(*stat));
descriptor->Stat(*stat);
return 0;
}


Expand Down

0 comments on commit 59ae1c8

Please sign in to comment.