Added a new method Inode::GetName() which safely copies the inode's name
to the provided buffer. Inode::Name() no longer locks the small_data region anymore. Added ASSERTs that the small_data region is locked for the methods requiring that. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2083 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -254,6 +254,8 @@ Inode::RemoveIterator(AttributeIterator *iterator)
|
|||||||
status_t
|
status_t
|
||||||
Inode::MakeSpaceForSmallData(Transaction *transaction, const char *name, int32 bytes)
|
Inode::MakeSpaceForSmallData(Transaction *transaction, const char *name, int32 bytes)
|
||||||
{
|
{
|
||||||
|
ASSERT(fSmallDataLock.IsLocked());
|
||||||
|
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
small_data *item = Node()->small_data_start, *max = NULL;
|
small_data *item = Node()->small_data_start, *max = NULL;
|
||||||
int32 index = 0, maxIndex = 0;
|
int32 index = 0, maxIndex = 0;
|
||||||
@@ -315,6 +317,8 @@ Inode::MakeSpaceForSmallData(Transaction *transaction, const char *name, int32 b
|
|||||||
status_t
|
status_t
|
||||||
Inode::RemoveSmallData(small_data *item, int32 index)
|
Inode::RemoveSmallData(small_data *item, int32 index)
|
||||||
{
|
{
|
||||||
|
ASSERT(fSmallDataLock.IsLocked());
|
||||||
|
|
||||||
small_data *next = item->Next();
|
small_data *next = item->Next();
|
||||||
if (!next->IsLast(Node())) {
|
if (!next->IsLast(Node())) {
|
||||||
// find the last attribute
|
// find the last attribute
|
||||||
@@ -524,12 +528,14 @@ Inode::AddSmallData(Transaction *transaction, const char *name, uint32 type,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Inode::GetNextSmallData(small_data **smallData) const
|
Inode::GetNextSmallData(small_data **_smallData) const
|
||||||
{
|
{
|
||||||
if (!Node())
|
if (!Node())
|
||||||
RETURN_ERROR(B_ERROR);
|
RETURN_ERROR(B_ERROR);
|
||||||
|
|
||||||
small_data *data = *smallData;
|
ASSERT(fSmallDataLock.IsLocked());
|
||||||
|
|
||||||
|
small_data *data = *_smallData;
|
||||||
|
|
||||||
// begin from the start?
|
// begin from the start?
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
@@ -541,7 +547,7 @@ Inode::GetNextSmallData(small_data **smallData) const
|
|||||||
if (data->IsLast(Node()))
|
if (data->IsLast(Node()))
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
*smallData = data;
|
*_smallData = data;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -555,6 +561,8 @@ Inode::GetNextSmallData(small_data **smallData) const
|
|||||||
small_data *
|
small_data *
|
||||||
Inode::FindSmallData(const char *name) const
|
Inode::FindSmallData(const char *name) const
|
||||||
{
|
{
|
||||||
|
ASSERT(fSmallDataLock.IsLocked());
|
||||||
|
|
||||||
small_data *smallData = NULL;
|
small_data *smallData = NULL;
|
||||||
while (GetNextSmallData(&smallData) == B_OK) {
|
while (GetNextSmallData(&smallData) == B_OK) {
|
||||||
if (!strcmp(smallData->Name(), name))
|
if (!strcmp(smallData->Name(), name))
|
||||||
@@ -564,10 +572,15 @@ Inode::FindSmallData(const char *name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns a pointer to the node's name if present in the small data
|
||||||
|
* section, NULL otherwise.
|
||||||
|
* You need to hold the fSmallDataLock when you call this method
|
||||||
|
*/
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
Inode::Name() const
|
Inode::Name() const
|
||||||
{
|
{
|
||||||
SimpleLocker locker(fSmallDataLock);
|
ASSERT(fSmallDataLock.IsLocked());
|
||||||
|
|
||||||
small_data *smallData = NULL;
|
small_data *smallData = NULL;
|
||||||
while (GetNextSmallData(&smallData) == B_OK) {
|
while (GetNextSmallData(&smallData) == B_OK) {
|
||||||
@@ -578,6 +591,24 @@ Inode::Name() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Copies the node's name into the provided buffer.
|
||||||
|
* The buffer must be B_FILE_NAME_LENGTH bytes large.
|
||||||
|
*/
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Inode::GetName(char *buffer) const
|
||||||
|
{
|
||||||
|
SimpleLocker locker(fSmallDataLock);
|
||||||
|
|
||||||
|
const char *name = Name();
|
||||||
|
if (name == NULL)
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
strlcpy(buffer, name, B_FILE_NAME_LENGTH);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Changes or set the name of a file: in the inode small_data section only, it
|
/** Changes or set the name of a file: in the inode small_data section only, it
|
||||||
* doesn't change it in the parent directory's b+tree.
|
* doesn't change it in the parent directory's b+tree.
|
||||||
* Note that you need to write back the inode yourself after having called
|
* Note that you need to write back the inode yourself after having called
|
||||||
|
|||||||
@@ -169,10 +169,12 @@ class Inode : public CachedBlock {
|
|||||||
// small_data access methods
|
// small_data access methods
|
||||||
status_t MakeSpaceForSmallData(Transaction *transaction, const char *name, int32 length);
|
status_t MakeSpaceForSmallData(Transaction *transaction, const char *name, int32 length);
|
||||||
status_t RemoveSmallData(Transaction *transaction, const char *name);
|
status_t RemoveSmallData(Transaction *transaction, const char *name);
|
||||||
status_t AddSmallData(Transaction *transaction,const char *name,uint32 type,const uint8 *data,size_t length,bool force = false);
|
status_t AddSmallData(Transaction *transaction, const char *name, uint32 type,
|
||||||
status_t GetNextSmallData(small_data **smallData) const;
|
const uint8 *data, size_t length, bool force = false);
|
||||||
|
status_t GetNextSmallData(small_data **_smallData) const;
|
||||||
small_data *FindSmallData(const char *name) const;
|
small_data *FindSmallData(const char *name) const;
|
||||||
const char *Name() const;
|
const char *Name() const;
|
||||||
|
status_t GetName(char *buffer) const;
|
||||||
status_t SetName(Transaction *transaction, const char *name);
|
status_t SetName(Transaction *transaction, const char *name);
|
||||||
|
|
||||||
// high-level attribute methods
|
// high-level attribute methods
|
||||||
@@ -204,8 +206,10 @@ class Inode : public CachedBlock {
|
|||||||
status_t Sync();
|
status_t Sync();
|
||||||
|
|
||||||
// create/remove inodes
|
// create/remove inodes
|
||||||
status_t Remove(Transaction *transaction,const char *name,off_t *_id = NULL,bool isDirectory = false);
|
status_t Remove(Transaction *transaction, const char *name, off_t *_id = NULL,
|
||||||
static status_t Create(Transaction *transaction,Inode *parent,const char *name,int32 mode,int omode,uint32 type,off_t *_id = NULL,Inode **_inode = NULL);
|
bool isDirectory = false);
|
||||||
|
static status_t Create(Transaction *transaction, Inode *parent, const char *name,
|
||||||
|
int32 mode, int omode, uint32 type, off_t *_id = NULL, Inode **_inode = NULL);
|
||||||
|
|
||||||
// index maintaining helper
|
// index maintaining helper
|
||||||
void UpdateOldSize() { fOldSize = Size(); }
|
void UpdateOldSize() { fOldSize = Size(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user