Go to the FreeLists Home Page Home Signup Help Login
 



[openbeosstorage] || [Date Prev] [04-2002 Date Index] [Date Next] || [Thread Prev] [04-2002 Thread Index] [Thread Next]

[openbeosstorage] BDirectory <-> BEntry

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: openbeosstorage@xxxxxxxxxxxxx
  • Date: Tue, 9 Apr 2002 13:49:22 +0200 (MET DST)
Howdy,

well, I had the feeling, I missed something, and I was right. ;-)

I would like to turn StorageKit::Dir from DIR* into
StorageKit::FileDescriptor or rather directly use file descriptors in
BEntry/BDirectory. Only the POSIX API uses DIR*, the R5 VFS API
does not. So it actually does not make much sense to have it in our kernel
interface.

As the attached little test program shows, the DIR* returned by opendir()
seems to be only a file descriptor with some extra space to store a
dirent. It doesn't contain any relevant data for iterating over the dir's
entries and no reference to it is hold within the `system'.

Regarding the relationship between BEntry and BDirectory: As I see it, at
this time the only reason for BEntry to be a friend of BDirectory concerns
the implementation of 
BEntry::SetTo(const BDirectory *dir, const char *path, bool traverse).
Since BDirectory::FindEntry() offers the same functionality, I suggest to
move the actual implementation into the latter. I would do that, as soon
as I start with the class implementation of BDirectory, which might be
in a couple days from now.

CU, Ingo


-- Attached file included as plaintext by Ecartis --
-- File: dir-test.cpp

// dir-test.cpp

#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>

int
main()
{
        const char *dirname = "/tmp";
        if (DIR *dir = opendir(dirname)) {
                while (dirent *ent = readdir(dir))
                        printf("name: `%s'\n", ent->d_name);
                closedir(dir);
        } else
                printf("Failed to open dir.\n");

        printf("\n");
        if (DIR *dir = opendir(dirname)) {
                // note the dir's fd and free the DIR structure
                int dirFd = dir->fd;
                free(dir);
                dir = NULL;
                // create two DIR clones
                DIR* dir2 = (DIR*)malloc(sizeof(DIR) + NAME_MAX);
                dir2->fd = dirFd;
                DIR* dir3 = (DIR*)malloc(sizeof(DIR) + NAME_MAX);
                dir3->fd = dirFd;
                // read one entry from one and the others from the other
                readdir(dir3);
                while (dirent *ent = readdir(dir2))
                        printf("name: `%s'\n", ent->d_name);
                // close/free the clones
                if (closedir(dir2) != 0)
                        printf("Failed to close dir2.\n");
                free(dir3);
        } else
                printf("Failed to open dir.\n");

        return 0;
}







[ Home | Signup | Help | Login | Archives | Lists ]

All trademarks and copyrights within the FreeLists archives are owned by their respective owners.
Everything else ©2007 Avenir Technologies, LLC.