From df8aa69a763b5aaf61602354e039330ec03ed447 Mon Sep 17 00:00:00 2001 From: "Bruno G. Albuquerque" Date: Wed, 20 Aug 2008 15:48:37 +0000 Subject: [PATCH] - Created a static version of Attribute::IsProtectedNamespace() that takes an attribute name as input. Handy for whyen we do not have an Attribute object around. - Made the non-static version fall back to the static version. - Also check for the protected namespace when creating attributes. For consistency, we should also not be able to create attributes in this namespace. - Added some new style violations. ;) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27082 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/cdda/kernel_interface.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp b/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp index 4d2eb411eb..6173651746 100644 --- a/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp @@ -148,6 +148,7 @@ class Attribute : public DoublyLinkedListLinkImpl { uint8* Data() const { return fData; } bool IsProtectedNamespace(); + static bool IsProtectedNamespace(const char* name); private: char* fName; @@ -1052,9 +1053,18 @@ Attribute::IsProtectedNamespace() { // Check if the attribute is in the restricted namespace. Attributes in // this namespace should not be edited by the user as they are handled - // internally by the add-on. - return strncmp(kProtectedAttrNamespace, fName, - strlen(kProtectedAttrNamespace)) == 0; + // internally by the add-on. Calls the static version. + return IsProtectedNamespace(fName); +} + + +bool +Attribute::IsProtectedNamespace(const char* name) +{ + // Convenience static version of the above method. Usually called when we + // don't have a constructed Attribute object handy. + return strncmp(kProtectedAttrNamespace, name, + strlen(kProtectedAttrNamespace)) == 0; } @@ -1932,10 +1942,14 @@ cdda_create_attr(fs_volume* _volume, fs_vnode* _node, const char* name, Attribute* attribute = inode->FindAttribute(name); if (attribute == NULL) { + if (Attribute::IsProtectedNamespace(name)) + return B_NOT_ALLOWED; status_t status = inode->AddAttribute(name, type, true, NULL, 0); if (status < B_OK) return status; } else if ((openMode & O_EXCL) == 0) { + if (attribute->IsProtectedNamespace()) + return B_NOT_ALLOWED; attribute->SetType(type); if ((openMode & O_TRUNC) != 0) attribute->Truncate();