Loading...
Searching...
No Matches
Public Member Functions | List of all members
BNode Class Reference

A BNode represents a chunk of data in the filesystem. More...

Inherits BStatable.

Inherited by BDirectory, BFile, and BSymLink.

Public Member Functions

 BNode ()
 Creates an uninitialized BNode object.
 
 BNode (const BDirectory *dir, const char *path)
 Creates a BNode object and initializes it to the entry referred to by the specified path rooted in the specified directory.
 
 BNode (const BEntry *entry)
 Creates a BNode object and initializes it to the specified filesystem entry.
 
 BNode (const BNode &node)
 Creates a copy of the given BNode.
 
 BNode (const char *path)
 Creates a BNode object and initializes it to the entry referred to by the specified path.
 
 BNode (const entry_ref *ref)
 Creates a BNode object and initializes it to the specified entry_ref.
 
virtual ~BNode ()
 Frees all resources associated with the BNode.
 
int Dup ()
 Gets the POSIX file descriptor referred to by this node.
 
virtual status_t GetStat (struct stat *st) const
 Fills in the given stat structure with the stat() information for this object.
 
Constructor Helpers
status_t InitCheck () const
 Checks whether the object has been properly initialized or not.
 
status_t SetTo (const entry_ref *ref)
 Initializes the object to the specified entry_ref.
 
status_t SetTo (const BEntry *entry)
 Initializes the object to the specified filesystem entry.
 
status_t SetTo (const char *path)
 Initializes the object to the specified path.
 
status_t SetTo (const BDirectory *dir, const char *path)
 Initializes the object to the entry referred by the specified path relative to the the specified directory.
 
void Unset ()
 Returns the object to an uninitialized state.
 
Locking Methods
status_t Lock ()
 Attains an exclusive lock on the data referred to by this node so that it may not be modified by any other objects or methods.
 
status_t Unlock ()
 Unlocks the date referred to by this node.
 
status_t Sync ()
 Immediately performs any pending disk actions on the node.
 
Attribute Methods
ssize_t WriteAttr (const char *name, type_code type, off_t offset, const void *buffer, size_t length)
 Writes data from a buffer to an attribute.
 
ssize_t ReadAttr (const char *name, type_code type, off_t offset, void *buffer, size_t length) const
 Reads data from an attribute into buffer.
 
status_t RemoveAttr (const char *name)
 Deletes the attribute given by name.
 
status_t RenameAttr (const char *oldName, const char *newName)
 Moves the attribute given by oldName to newName.
 
status_t GetAttrInfo (const char *name, struct attr_info *info) const
 Fills in the pre-allocated attr_info struct pointed to by info with information about the attribute specified by name.
 
status_t GetNextAttrName (char *buffer)
 Copies the name of the attribute into buffer and then advances the pointer to the next attribute.
 
status_t RewindAttrs ()
 Resets the object's attribute pointer to the first attribute in the list.
 
status_t WriteAttrString (const char *name, const BString *data)
 Writes the specified string to the specified attribute, clobbering any previous data.
 
status_t ReadAttrString (const char *name, BString *result) const
 Reads the data of the specified attribute into the pre-allocated result.
 
Operators
BNodeoperator= (const BNode &node)
 Initializes the object as a copy of other.
 
bool operator== (const BNode &node) const
 Tests whether this and the supplied BNode object are equal.
 
bool operator!= (const BNode &node) const
 Tests whether this and the supplied BNode object are not equal.
 
- Public Member Functions inherited from BStatable
status_t GetAccessTime (time_t *atime) const
 Fills out atime with the access time of the node.
 
status_t GetCreationTime (time_t *ctime) const
 Fills out ctime with the creation time of the node.
 
status_t GetGroup (gid_t *group) const
 Fills out the node's GID into group.
 
status_t GetModificationTime (time_t *mtime) const
 Fills out mtime with the last modification time of the node.
 
status_t GetNodeRef (node_ref *ref) const
 Fills out ref with the node_ref of the node.
 
status_t GetOwner (uid_t *owner) const
 Fills out the node's UID into owner.
 
status_t GetPermissions (mode_t *permissions) const
 Fills out perms with the permissions of the node.
 
status_t GetSize (off_t *size) const
 Fills out the size of the node's data (not counting attributes) into size.
 
virtual status_t GetStat (struct stat *stat) const =0
 Fills out the stat structure for the node.
 
status_t GetVolume (BVolume *volume) const
 Fills out vol with the the volume that the node lives on.
 
bool IsDirectory () const
 Returns whether or not the node is a directory.
 
bool IsFile () const
 Returns whether or not the node is a file.
 
bool IsSymLink () const
 Returns whether or not the node is a symbolic link.
 
status_t SetAccessTime (time_t atime)
 Sets the node's access time to atime.
 
status_t SetCreationTime (time_t ctime)
 Sets the node's creation time to ctime.
 
status_t SetGroup (gid_t group)
 Sets the node's GID to group.
 
status_t SetModificationTime (time_t mtime)
 Sets the node's last modification time to mtime.
 
status_t SetOwner (uid_t owner)
 Sets the node's UID to owner.
 
status_t SetPermissions (mode_t permissions)
 Sets the node's permissions to perms.
 

Detailed Description

A BNode represents a chunk of data in the filesystem.

The BNode class provides an interface for manipulating the data and attributes belonging to filesystem entries. The BNode is unaware of the name that refers to it in the filesystem (i.e. its entry), instead, a BNode is concerned solely with the entry's data and attributes.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BNode() [1/6]

BNode::BNode ( )

Creates an uninitialized BNode object.

See also
SetTo()
Since
BeOS R3

◆ BNode() [2/6]

BNode::BNode ( const entry_ref ref)

Creates a BNode object and initializes it to the specified entry_ref.

Parameters
refThe entry_ref referring to the node.
Since
BeOS R3

◆ BNode() [3/6]

BNode::BNode ( const BEntry entry)

Creates a BNode object and initializes it to the specified filesystem entry.

Parameters
entryThe BEntry referring to the node.
Since
BeOS R3

◆ BNode() [4/6]

BNode::BNode ( const char *  path)

Creates a BNode object and initializes it to the entry referred to by the specified path.

Parameters
pathThe path referring to the node.
Since
BeOS R3

◆ BNode() [5/6]

BNode::BNode ( const BDirectory dir,
const char *  path 
)

Creates a BNode object and initializes it to the entry referred to by the specified path rooted in the specified directory.

Parameters
dirThe base BDirectory.
pathThe path name relative to dir.
Since
BeOS R3

◆ BNode() [6/6]

BNode::BNode ( const BNode other)

Creates a copy of the given BNode.

Parameters
otherThe BNode to be copied.
Since
BeOS R3

◆ ~BNode()

BNode::~BNode ( )
virtual

Frees all resources associated with the BNode.

Since
BeOS R3

Member Function Documentation

◆ Dup()

int BNode::Dup ( )

Gets the POSIX file descriptor referred to by this node.

Remember to call close() on the file descriptor when you're through with it.

Returns
A valid file descriptor, or -1 if something went wrong.
Since
Haiku R1

◆ GetAttrInfo()

status_t BNode::GetAttrInfo ( const char *  name,
struct attr_info *  info 
) const

Fills in the pre-allocated attr_info struct pointed to by info with information about the attribute specified by name.

Parameters
nameThe name of the attribute.
infoThe attr_info structure to be filled in.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEname was NULL.
B_FILE_ERRORThe object was not initialized.
B_ENTRY_NOT_FOUNDThe node had no attribute name.
Since
BeOS R3

◆ GetNextAttrName()

status_t BNode::GetNextAttrName ( char *  buffer)

Copies the name of the attribute into buffer and then advances the pointer to the next attribute.

The name of the node is first copied into buffer, which should be at least B_ATTR_NAME_LENGTH characters long. The copied node name is \0 terminated. Once the name is copied the attribute list pointer is advanced to the next attribute in the list. When GetNextAttrName() reaches the end of the list it returns B_ENTRY_NOT_FOUND.

Parameters
bufferA buffer to copy the name of the attribute into.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKThe Attribute name was copied and there are more attribute names to copy.
B_BAD_VALUEpassed in buffer was NULL.
B_FILE_ERRORThe object was not initialized.
B_ENTRY_NOT_FOUNDThere were no more attributes, the last attribute name had already been copied.
Since
BeOS R3

◆ GetStat()

status_t BNode::GetStat ( struct stat *  stat) const
virtual

Fills in the given stat structure with the stat() information for this object.

Parameters
statA pointer to a stat structure to be filled in.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUENULL stat.
Since
Haiku R1

Implements BStatable.

◆ InitCheck()

status_t BNode::InitCheck ( ) const

Checks whether the object has been properly initialized or not.

Returns
B_OK if the object has been properly initialized, or B_NO_INIT otherwise.
Since
BeOS R3

◆ Lock()

status_t BNode::Lock ( )

Attains an exclusive lock on the data referred to by this node so that it may not be modified by any other objects or methods.

Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_FILE_ERRORThe object is not initialized.
B_BUSYThe node is already locked.
Since
BeOS R3

◆ operator!=()

bool BNode::operator!= ( const BNode node) const

Tests whether this and the supplied BNode object are not equal.

Two BNode objects are said to be equal if they're set to the same node, or if they're both unintialized.

Parameters
nodeThe BNode to be compared with
Returns
false, if the BNode objects are equal, true otherwise.
Since
BeOS R3

◆ operator=()

BNode & BNode::operator= ( const BNode other)

Initializes the object as a copy of other.

Parameters
otherthe BNode to be copied.
Returns
A reference to this BNode object.
Since
BeOS R3

◆ operator==()

bool BNode::operator== ( const BNode node) const

Tests whether this and the supplied BNode object are equal.

Two BNode objects are said to be equal if they're set to the same node, or if they're both unintialized

Parameters
nodeThe BNode to be compared against.
Returns
true, if the BNode objects are equal, false otherwise.
Since
BeOS R3

◆ ReadAttr()

ssize_t BNode::ReadAttr ( const char *  attr,
type_code  type,
off_t  offset,
void *  buffer,
size_t  length 
) const

Reads data from an attribute into buffer.

Reads length bytes of data from the attribute given by name into buffer. type and offset are currently ignored.

Parameters
attrThe name of the attribute.
typeThe type of the attribute (currently ignored).
offsetThe index from which to read the data (currently ignored).
bufferThe buffer for the data to be read.
lengthThe number of bytes to be read.
Returns
The number of bytes actually read.
Return values
B_BAD_VALUEattr or buffer was NULL.
B_FILE_ERRORThe object was not initialized.
B_ENTRY_NOT_FOUNDThe node had no attribute attr.
Since
BeOS R3

◆ ReadAttrString()

status_t BNode::ReadAttrString ( const char *  name,
BString result 
) const

Reads the data of the specified attribute into the pre-allocated result.

Parameters
namethe name of the attribute.
resultthe BString to be set to the value of the attribute.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEname or result was NULL.
B_FILE_ERRORThe object was not initialized.
B_ENTRY_NOT_FOUNDThe node had no attribute attr.
Since
Haiku R1

◆ RemoveAttr()

status_t BNode::RemoveAttr ( const char *  name)

Deletes the attribute given by name.

Parameters
nameThe name of the attribute to remove.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEname was NULL.
B_FILE_ERRORThe object was not initialized or the node it referred to was read-only.
B_ENTRY_NOT_FOUNDThe node had no attribute name.
B_NOT_ALLOWEDThe node resided on a read-only volume.
Since
BeOS R3

◆ RenameAttr()

status_t BNode::RenameAttr ( const char *  oldName,
const char *  newName 
)

Moves the attribute given by oldName to newName.

If newName already exists, the data is clobbered.

Parameters
oldNameThe name of the attribute to be renamed.
newNameThe new name for the attribute.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEoldName or newName was NULL.
B_FILE_ERRORThe object was not initialized or the node it referred to was read only.
B_ENTRY_NOT_FOUNDThe node had no attribute oldName.
B_NOT_ALLOWEDThe node resided on a read-only volume.
Since
BeOS R3

◆ RewindAttrs()

status_t BNode::RewindAttrs ( )

Resets the object's attribute pointer to the first attribute in the list.

Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_FILE_ERRORSome other error occurred.
Since
BeOS R3

◆ SetTo() [1/4]

status_t BNode::SetTo ( const BDirectory dir,
const char *  path 
)

Initializes the object to the entry referred by the specified path relative to the the specified directory.

Parameters
dirThe base BDirectory.
pathThe path name relative to dir.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEdir was NULL.
B_ENTRY_NOT_FOUNDThe entry could not be found.
B_BUSYThe entry was locked.
Since
BeOS R3

◆ SetTo() [2/4]

status_t BNode::SetTo ( const BEntry entry)

Initializes the object to the specified filesystem entry.

Parameters
entryThe BEntry representing the entry.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEentry was NULL.
B_ENTRY_NOT_FOUNDThe entry could not be found.
B_BUSYThe entry was locked.
Since
BeOS R3

◆ SetTo() [3/4]

status_t BNode::SetTo ( const char *  path)

Initializes the object to the specified path.

Parameters
pathThe entry's path name; path can be relative or absolute, and can contain "." and ".." elements. If path is relative, it uses the current working directory as the base directory.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEpath was NULL.
B_ENTRY_NOT_FOUNDThe entry could not be found.
B_BUSYThe entry of was locked.
Since
BeOS R3

◆ SetTo() [4/4]

status_t BNode::SetTo ( const entry_ref ref)

Initializes the object to the specified entry_ref.

Parameters
refThe entry_ref referring to the entry.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEref was NULL.
B_ENTRY_NOT_FOUNDThe entry could not be found.
B_BUSYThe entry was locked.
Since
BeOS R3

◆ Sync()

status_t BNode::Sync ( )

Immediately performs any pending disk actions on the node.

Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_FILE_ERRORSomething went wrong.
Since
BeOS R3

◆ Unlock()

status_t BNode::Unlock ( )

Unlocks the date referred to by this node.

Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_FILE_ERRORThe object is not initialized.
B_BAD_VALUEThe node is not locked.
Since
BeOS R3

◆ Unset()

void BNode::Unset ( )

Returns the object to an uninitialized state.

Since
BeOS R3

◆ WriteAttr()

ssize_t BNode::WriteAttr ( const char *  attr,
type_code  type,
off_t  offset,
const void *  buffer,
size_t  length 
)

Writes data from a buffer to an attribute.

Write length bytes of data from buffer to the attribute specified by name after erasing any data that existed previously. The type specified by type is remembered, and may be queried with GetAttrInfo(). The value of offset is currently ignored.

Parameters
attrThe name of the attribute.
typeThe type of the attribute.
offsetThe index at which to write the data (currently ignored).
bufferThe buffer containing the data to be written.
lengthThe number of bytes to be written.
Returns
The number of bytes actually written.
Return values
B_BAD_VALUEattr or buffer was NULL.
B_FILE_ERRORThe object was not initialized or the node it refers to was read only.
B_NOT_ALLOWEDThe node resides on a read only volume.
B_DEVICE_FULLThere was insufficient disk space to complete the operation.
B_NO_MEMORYThere was insufficient memory to complete the operation.
Since
BeOS R3

◆ WriteAttrString()

status_t BNode::WriteAttrString ( const char *  name,
const BString data 
)

Writes the specified string to the specified attribute, clobbering any previous data.

Parameters
namethe name of the attribute.
datathe BString to be written to the attribute.
Returns
B_OK on success or an error code otherwise.
Return values
B_OKEverything went fine.
B_BAD_VALUEname or data was NULL.
B_FILE_ERRORThe object was not initialized or the node it referred to was read-only.
B_NOT_ALLOWEDThe node resided on a read-only volume.
B_DEVICE_FULLThere was insufficient disk space to complete the operation.
B_NO_MEMORYThere was insufficient memory to complete the operation.
Since
Haiku R1