Remove()
does not invalidate the
BEntry
. It simply makes it abstract
(see "Abstract Entries").
| Class Overview |
BEntry();
BEntry(const BDirectory
* dir,
const char* path,
bool traverse = false);
BEntry(const entry_ref* entry,
bool traverse = false);
BEntry(const char* path,
bool traverse = false);
BEntry(const BEntry& entry);
Creates a new BEntry
object that represents the entry described by the
arguments. See the analogous
SetTo()
functions for descriptions of the flavorful constructors.
The default constructor does nothing; it should be followed by a call to
SetTo()
.
The copy constructor points the new object to the entry that's represented by the argument. The two objects themselves maintain separate representation of the entry; in other words, they each contain their own a) file descriptor and b) string to identify the entry's a) directory and b) name.
To see if the initialization was successful, call
InitCheck()
.
status_t GetName(char* buffer) const;
status_t GetPath(BPath
* path) const;
These functions return the leaf name and full pathname of the BEntry
's
entry. The arguments must be allocated before they're passed in.
GetName()
copies the leaf name into buffer
. The buffer
must be large
enough to accommodate the name; B_FILE_NAME_LENGTH
is a 100% safe bet:
charname
[B_FILE_NAME_LENGTH
];entry
.GetName
(name
);
If GetName()
fails, *buffer
is pointed at NULL
.
GetPath()
takes the entry's full pathname and initializes the
BPath
argument with it. To retrieve the path from the
BPath
object, call
BPath::Path()
:
BPath
path
;entry
.GetPath
(&path
);printf
(">Entry pathname: %sn",path
.Path()
);
If GetPath()
fails, the argument is
Unset()
.
Return Code | Description |
---|---|
| The information was successfully retrieved. |
| The |
| ( |
status_t GetParent(BEntry* entry) const;
status_t GetParent(BDirectory
* dir) const;
Gets the directory, as a BEntry
or
BDirectory
object, in which the
object's entry lives. The argument must be allocated before it's passed
in.
If the function is unsuccessful, the argument is
Unset()
. Because of
this, you should be particularly careful if you're using the
BEntry
-argument version to destructively get a
BEntry
's parent:
if (entry
.GetParent
(&entry
) !=B_OK
) { /* you just lost 'entry' */ }
This example is legal; for example, you can use destructive iteration to
loop your way up to the root directory. When you reach the root ("/"),
GetParent()
returns B_ENTRY_NOT_FOUND
:
BEntry
entry
("/boot/home/fido"); status_terr
; charname
[B_FILE_NAME_LENGTH
]; /* Spit out the path components backwards, one at a time. */ do {entry
.GetName
(name
);printf
("> %sn",name
); } while ((err
=entry
.GetParent
(&entry
)) ==B_OK
); /* Complain for reasons other than reaching the top. */ if (err
!=B_ENTRY_NOT_FOUND
)printf
(">> Error: %sn",strerror
(err
));
This produces:
> fido > home > boot > /
Return Code | Description |
---|---|
| The information was successfully retrieved. |
| This |
| Attempt to get the parent of the root directory. |
| Couldn't get another file descriptor. |
status_t GetRef(entry_ref* ref) const;
Gets the entry_ref for the object's entry; ref
must be allocated before
it's passed in. As with BEntry
objects, entry_ref structures can be
abstract—getting a valid entry_ref does not guarantee that the
entry actually exists.
If the function isn't successful, ref
is unset.
Return Code | Description |
---|---|
| The entry_ref was successfully retrieved. |
| This object isn't initialized. |
| Storage for the entry_ref's name couldn't be allocated. |
virtual status_t GetStat(struct stat* st) const;
GetStat()
returns the stat structure for the entry. The structure is
copied into the st
argument, which must be allocated. The
BStatable
object does not cache the stat structure; every time you call
GetStat()
,
fresh stat information is retrieved.
Return Code | Description |
---|---|
| Success. |
| Couldn't get the necessary resources to complete the transaction. |
| The entry doesn't exist (abstract entry). |
status_t InitCheck() const;
Returns the status of the previous construction, assignment operation, or
SetTo()
call.
Return Code | Description |
---|---|
| The initialization was successful. |
| The object is uninitialized (this includes
|
Other errors. | See |
status_t Remove();
Remove()
"unlinks" the entry from its directory. The entry's node isn't
destroyed until all file descriptors that are open on the node are
closed. This means that if you create
BFile
based on
a BEntry
, and then
Remove()
the BEntry
, the
BFile
will still be
able to read and write the
file's data—the BFile
has no way of knowing that the entry is gone.
When the BFile
is deleted, the node will be destroyed as well.
Remove()
does not invalidate the
BEntry
. It simply makes it abstract
(see "Abstract Entries").
Return Code | Description |
---|---|
| Success. |
| The |
| The entry's directory is locked. |
status_t Rename(const char* path,
bool clobber = false);
status_t MoveTo(BDirectory
* dir,
const char* path = NULL,
bool clobber = false);
These functions move the BEntry
's entry and node to a new location. In
both cases, the BEntry
must not be abstract—you can't rename or
move an abstract entry.
Rename()
moves the entry to a new name, as given
by path
. path
is usually
a simple leaf name, but it can be a relative path. In the former case
(simple leaf) the entry is renamed within its current directory. In the
latter, the entry is moved into a subdirectory of its current directory,
as given by the argument.
MoveTo()
moves the entry to a different directory and optionally renames
the leaf. Again, path
can be a simple leaf or a relative path; in both
cases, path
is reckoned off of dir
.
If path is NULL
, the entry is moved
to dir
, but retains its old leaf name.
If the entry's new location is already taken, the clobber argument
decides whether the existing entry is removed to make way for yours. If
it's true
, the existing entry is removed; if it's
false
, the Rename()
or
MoveTo()
function fails.
Upon success, this is updated to reflect the change to its entry. For
example, when you invoke Rename()
on a
BEntry
, the name of that specific
BEntry
object also changes. If the rename or move-to isn't successful,
this isn't altered.
Return Code | Description |
---|---|
| Success. |
| The |
| A directory to the new location doesn't exist, or this is an abstract entry. |
| The new location is already taken (and you're not clobbering). |
| The directory that you're moving the entry into is locked. |
status_t SetTo(const entry_ref* ref,
bool traverse = false);
status_t SetTo(const char* path,
bool traverse = false);
status_t SetTo(const BDirectory
* dir,
const char* path,
bool traverse = false);
void Unset();
Frees the BEntry
's current entry reference, and initializes it to refer
to the entry identified by the argument(s):
In the ref
version, the BEntry
is initialized to refer to the given
entry_ref.
In the path
version, path
can be absolute or relative, and can
contain "." and ".." elements. If path
is relative, it's reckoned off
of the current working directory.
In the dir
/path
version,
path
must be relative. It's reckoned off of
the directory given by dir
.
The traverse
argument is used to resolve (or not) entries that are
symlinks:
If traverse
is true
, the link is resolved.
If traverse
is false
,
the BEntry
refers to the link itself.
See "Initializing and Traversing" for more information.
When you initialize a BEntry
, you're describing a leaf name within a
directory. The directory must exist, but the leaf doesn't have to. This
allows you to create a BEntry
to a file that doesn't exist (yet). See
"Abstract Entries" for more information.
Remember—successfully initializing a BEntry
consumes a file
descriptor. When you re-initialize, the old file descriptor is closed.
Unset()
removes the object's association with its current entry, and sets
InitCheck()
to B_NO_INIT
.
Return Code | Description |
---|---|
| The |
| Bad argument value; uninitialized
|
| A directory in the path to the entry doesn't exist. |
| The entry's directory is locked. |
BEntry& operator=(const BEntry& entry);
In the expression
BEntry
a
=b
;
BEntry
a
is initialized to refer
to the same entry as b
. To gauge the
success of the assignment, you should call
InitCheck()
immediately afterwards. Assigning a BEntry
to itself is safe.
Assigning from an uninitialized BEntry
is "successful": The assigned-to
BEntry
will also be uninitialized (B_NO_INIT
).
status_t get_ref_for_path(const char* path,
entry_ref* ref);
Returns in ref
an entry_ref
for the file specified by the path
argument.
Return Code | Description |
---|---|
| The ref was returned successfully. |
| The file wasn't found, or the pathname string is empty. |
| Not enough memory. |
Other file errors. |
Declared in: storage/Entry.h
struct entry_ref {entry_ref
();entry_ref
(dev_tdevice
, ino_tdir
, const char*name
);entry_ref
(const entry_ref&ref
);~entry_ref
(); status_tset_name
(const char*name
); booloperator==
(const entry_ref&ref
) const; booloperator!=
(const entry_ref&ref
) const; entry_ref&operator=
(const entry_ref&ref
); dev_tdevice
; ino_tdirectory
; char*name
; }
The entry_ref structure describes a single entry in a directory.
device
contains the device number on which the entry's target is located.
directory
contains the inode of the directory that contains the entry's
target.
name
contains the name of the entry.
entry_ref();
entry_ref(const entry_ref& ref);
entry_ref(dev_t device,
ino_t dir,
const char* name);
The constructor for the entry_ref structure. The first of these creates an empty entry_ref, the second duplicates an existing entry_ref, and the last version of the constructor accepts a device number, directory inode number, and a file name and constructs an entry_ref referring to that entry.
~entry_ref();
The destructor for entry_ref.
status_t set_name(const char* name);
Lets you change the name of the file referred to by the entry_ref structure.
operator ==
Lets you perform comparisons of entry_ref structures to see if they refer to the same entry.
operator !=
Lets you test to see if two entry_ref structures refer to different entries.