2 * Copyright 2003-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
11 #include <StorageDefs.h>
12 #include <KernelExport.h>
18 // temp. private VFS API
19 extern Node
*get_node_from(int fd
);
28 Directory::Directory(Volume
&volume
, block_run run
)
36 Directory::Directory(Volume
&volume
, off_t id
)
44 Directory::Directory(const Stream
&stream
)
52 Directory::~Directory()
58 Directory::InitCheck()
60 return fStream
.InitCheck();
65 Directory::Open(void **_cookie
, int mode
)
67 _inherited::Open(_cookie
, mode
);
69 *_cookie
= (void *)new(nothrow
) TreeIterator(&fTree
);
78 Directory::Close(void *cookie
)
80 _inherited::Close(cookie
);
82 delete (TreeIterator
*)cookie
;
88 Directory::LookupDontTraverse(const char* name
)
91 if (fTree
.Find((uint8
*)name
, strlen(name
), &id
) < B_OK
)
94 return Stream::NodeFactory(fStream
.GetVolume(), id
);
99 Directory::GetNextEntry(void *cookie
, char *name
, size_t size
)
101 TreeIterator
*iterator
= (TreeIterator
*)cookie
;
105 return iterator
->GetNextEntry(name
, &length
, size
, &id
);
110 Directory::GetNextNode(void *cookie
, Node
**_node
)
112 TreeIterator
*iterator
= (TreeIterator
*)cookie
;
113 char name
[B_FILE_NAME_LENGTH
];
117 status_t status
= iterator
->GetNextEntry(name
, &length
, sizeof(name
), &id
);
121 *_node
= Stream::NodeFactory(fStream
.GetVolume(), id
);
130 Directory::Rewind(void *cookie
)
132 TreeIterator
*iterator
= (TreeIterator
*)cookie
;
134 return iterator
->Rewind();
141 TreeIterator
iterator(&fTree
);
143 // index and attribute directories are really empty when they are
144 // empty - directories for standard files always contain ".", and
145 // "..", so we need to ignore those two
148 char name
[BPLUSTREE_MAX_KEY_LENGTH
];
151 while (iterator
.GetNextEntry(name
, &length
, B_FILE_NAME_LENGTH
, &id
)
153 if (fStream
.Mode() & (S_ATTR_DIR
| S_INDEX_DIR
))
156 if (++count
> 2 || (strcmp(".", name
) && strcmp("..", name
)))
164 Directory::GetName(char *name
, size_t size
) const
166 if (fStream
.inode_num
== fStream
.GetVolume().Root()) {
167 strlcpy(name
, fStream
.GetVolume().SuperBlock().name
, size
);
171 return fStream
.GetName(name
, size
);
176 Directory::Inode() const