first round of style cleanup on ramfs driver; change node _dir to pointer in ramfs_lookup function

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42036 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV 2011-06-08 00:42:51 +00:00
parent 1b7d2a5498
commit f76a033d04

View File

@ -109,6 +109,7 @@ ramfs_mount(dev_t nsid, const char* /*device*/, uint32 flags,
RETURN_ERROR(B_OK);
}
// ramfs_unmount
static status_t
ramfs_unmount(fs_volume* _volume)
@ -124,6 +125,7 @@ ramfs_unmount(fs_volume* _volume)
return error;
}
// ramfs_read_fs_info
static status_t
ramfs_read_fs_info(fs_volume* _volume, struct fs_info *info)
@ -139,7 +141,8 @@ ramfs_read_fs_info(fs_volume* _volume, struct fs_info *info)
info->total_blocks = volume->CountBlocks();
info->free_blocks = volume->CountFreeBlocks();
info->device_name[0] = '\0';
strncpy(info->volume_name, volume->GetName(), sizeof(info->volume_name));
strncpy(info->volume_name, volume->GetName(),
sizeof(info->volume_name));
strcpy(info->fsh_name, "ramfs");
} else
SET_ERROR(error, B_ERROR);
@ -163,6 +166,7 @@ ramfs_write_fs_info(fs_volume* _volume, const struct fs_info *info, uint32 mask)
RETURN_ERROR(error);
}
// ramfs_sync
static status_t
ramfs_sync(fs_volume /*fs*/)
@ -177,14 +181,15 @@ ramfs_sync(fs_volume /*fs*/)
// ramfs_lookup
static status_t
ramfs_lookup(fs_volume* _volume, fs_vnode _dir, const char *entryName, ino_t *vnid,
int *type)
ramfs_lookup(fs_volume* _volume, fs_vnode* _dir, const char *entryName,
ino_t *vnid, int *type)
{
// FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
Directory *dir = dynamic_cast<Directory*>((Node*)_dir);
FUNCTION(("dir: (%llu), entry: `%s'\n", (dir ? dir->GetID() : -1), entryName));
FUNCTION(("dir: (%llu), entry: `%s'\n", (dir ? dir->GetID() : -1),
entryName));
// check for non-directories
if (!dir)
@ -223,6 +228,7 @@ SET_ERROR(error, error);
RETURN_ERROR(error);
}
// ramfs_read_vnode
static status_t
ramfs_read_vnode(fs_volume* _volume, ino_t vnid, fs_vnode* node, bool reenter)
@ -241,6 +247,7 @@ FUNCTION(("node: %Ld\n", vnid));
RETURN_ERROR(error);
}
// ramfs_write_vnode
static status_t
ramfs_write_vnode(fs_volume /*fs*/, fs_vnode DARG(_node), bool /*reenter*/)
@ -256,6 +263,7 @@ ramfs_write_vnode(fs_volume /*fs*/, fs_vnode DARG(_node), bool /*reenter*/)
RETURN_ERROR(error);
}
// ramfs_remove_vnode
static status_t
ramfs_remove_vnode(fs_volume* _volume, fs_vnode _node, bool /*reenter*/)
@ -279,9 +287,8 @@ ramfs_remove_vnode(fs_volume* _volume, fs_vnode _node, bool /*reenter*/)
// ramfs_ioctl
static status_t
ramfs_ioctl(fs_volume* _volume, fs_vnode /*node*/, fs_cookie /*cookie*/, uint32 cmd,
void *buffer, size_t /*length*/)
ramfs_ioctl(fs_volume* _volume, fs_vnode /*node*/, fs_cookie /*cookie*/,
uint32 cmd, void *buffer, size_t /*length*/)
{
FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
@ -327,16 +334,18 @@ PRINT((" RAMFS_IOCTL_DUMP_INDEX, `%s'\n", name));
RETURN_ERROR(error);
}
// ramfs_set_flags
static status_t
ramfs_set_flags(fs_volume /*fs*/, fs_vnode /*node*/, fs_cookie /*cookie*/,
int /*flags*/)
{
FUNCTION_START();
// TODO:...
// TODO : ramfs_set_flags
return B_OK;
}
// ramfs_fsync
static status_t
ramfs_fsync(fs_volume /*fs*/, fs_vnode /*node*/)
@ -345,6 +354,7 @@ ramfs_fsync(fs_volume /*fs*/, fs_vnode /*node*/)
return B_OK;
}
// ramfs_read_symlink
static status_t
ramfs_read_symlink(fs_volume* _volume, fs_vnode _node, char *buffer,
@ -378,6 +388,7 @@ ramfs_read_symlink(fs_volume* _volume, fs_vnode _node, char *buffer,
RETURN_ERROR(error);
}
// ramfs_create_symlink
static status_t
ramfs_create_symlink(fs_volume* _volume, fs_vnode _dir, const char *name,
@ -435,6 +446,7 @@ ramfs_create_symlink(fs_volume* _volume, fs_vnode _dir, const char *name,
RETURN_ERROR(error);
}
// ramfs_link
static status_t
ramfs_link(fs_volume* _volume, fs_vnode _dir, const char *name, fs_vnode _node)
@ -478,6 +490,7 @@ ramfs_link(fs_volume* _volume, fs_vnode _dir, const char *name, fs_vnode _node)
RETURN_ERROR(error);
}
// ramfs_unlink
static status_t
ramfs_unlink(fs_volume* _volume, fs_vnode _dir, const char *name)
@ -522,6 +535,7 @@ ramfs_unlink(fs_volume* _volume, fs_vnode _dir, const char *name)
RETURN_ERROR(error);
}
// ramfs_rename
static status_t
ramfs_rename(fs_volume* _volume, fs_vnode _oldDir, const char *oldName,
@ -639,6 +653,7 @@ oldDir->GetID(), oldName, newDir->GetID(), newName));
RETURN_ERROR(error);
}
// ramfs_access
static status_t
ramfs_access(fs_volume* _volume, fs_vnode _node, int mode)
@ -655,6 +670,7 @@ ramfs_access(fs_volume* _volume, fs_vnode _node, int mode)
RETURN_ERROR(error);
}
// ramfs_read_stat
static status_t
ramfs_read_stat(fs_volume* _volume, fs_vnode _node, struct stat *st)
@ -683,6 +699,7 @@ ramfs_read_stat(fs_volume* _volume, fs_vnode _node, struct stat *st)
RETURN_ERROR(error);
}
// ramfs_write_stat
static status_t
ramfs_write_stat(fs_volume* _volume, fs_vnode _node, const struct stat *st,
@ -734,7 +751,8 @@ ramfs_write_stat(fs_volume* _volume, fs_vnode _node, const struct stat *st,
// FileCookie
class FileCookie {
public:
FileCookie(int openMode) : fOpenMode(openMode), fLastNotificationTime(0) {}
FileCookie(int openMode) : fOpenMode(openMode),
fLastNotificationTime(0) {}
inline int GetOpenMode() { return fOpenMode; }
@ -744,10 +762,12 @@ public:
inline bool NotificationIntervalElapsed(bool set = false)
{
bigtime_t currentTime = system_time();
bool result = (currentTime - fLastNotificationTime
bool result = (currentTime
- fLastNotificationTime
> kNotificationInterval);
if (set && result)
fLastNotificationTime = currentTime;
return result;
}
@ -756,6 +776,7 @@ private:
bigtime_t fLastNotificationTime;
};
// ramfs_create
static status_t
ramfs_create(fs_volume* _volume, fs_vnode _dir, const char *name, int openMode,
@ -800,8 +821,7 @@ ramfs_create(fs_volume* _volume, fs_vnode _dir, const char *name, int openMode,
} else if (!node->IsFile()) {
SET_ERROR(error, B_NOT_ALLOWED);
// the user must have write permission for an existing entry
} else if ((error = node->CheckPermissions(ACCESS_W))
== B_OK) {
} else if ((error = node->CheckPermissions(ACCESS_W)) == B_OK) {
// truncate, if requested
if (openMode & O_TRUNC)
error = node->SetSize(0);
@ -841,6 +861,7 @@ ramfs_create(fs_volume* _volume, fs_vnode _dir, const char *name, int openMode,
RETURN_ERROR(error);
}
// ramfs_open
static status_t
ramfs_open(fs_volume* _volume, fs_vnode _node, int openMode, fs_cookie *_cookie)
@ -883,6 +904,7 @@ ramfs_open(fs_volume* _volume, fs_vnode _node, int openMode, fs_cookie *_cookie)
RETURN_ERROR(error);
}
// ramfs_close
static status_t
ramfs_close(fs_volume* _volume, fs_vnode _node, fs_cookie /*cookie*/)
@ -902,6 +924,7 @@ ramfs_close(fs_volume* _volume, fs_vnode _node, fs_cookie /*cookie*/)
}
// ramfs_free_cookie
static status_t
ramfs_free_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
@ -912,6 +935,7 @@ ramfs_free_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
return B_OK;
}
// ramfs_read
static status_t
ramfs_read(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
@ -948,6 +972,7 @@ ramfs_read(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
RETURN_ERROR(error);
}
// ramfs_write
static status_t
ramfs_write(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
@ -1002,7 +1027,8 @@ ramfs_write(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
class DirectoryCookie {
public:
DirectoryCookie(Directory *directory = NULL)
: fIterator(directory),
:
fIterator(directory),
fDotIndex(DOT_INDEX),
// debugging
fIteratorID(atomic_add(&fNextIteratorID, 1)),
@ -1044,7 +1070,8 @@ fGetNextCounter++;
}
PRINT(("EntryIterator %ld, GetNext() counter: %ld, entry: %p (%Ld)\n",
fIteratorID, fGetNextCounter, fIterator.GetCurrent(),
(fIterator.GetCurrent() ? fIterator.GetCurrent()->GetNode()->GetID() : -1)));
(fIterator.GetCurrent()
? fIterator.GetCurrent()->GetNode()->GetID() : -1)));
return error;
}
@ -1073,8 +1100,11 @@ private:
int32 fGetNextCounter;
static vint32 fNextIteratorID;
};
vint32 DirectoryCookie::fNextIteratorID = 0;
// ramfs_create_dir
static status_t
ramfs_create_dir(fs_volume* _volume, fs_vnode _dir, const char *name, int mode)
@ -1131,6 +1161,7 @@ ramfs_create_dir(fs_volume* _volume, fs_vnode _dir, const char *name, int mode)
RETURN_ERROR(error);
}
// ramfs_remove_dir
static status_t
ramfs_remove_dir(fs_volume* _volume, fs_vnode _dir, const char *name)
@ -1175,6 +1206,7 @@ ramfs_remove_dir(fs_volume* _volume, fs_vnode _dir, const char *name)
RETURN_ERROR(error);
}
// ramfs_open_dir
static status_t
ramfs_open_dir(fs_volume /*fs*/, fs_vnode _node, fs_cookie *_cookie)
@ -1210,6 +1242,7 @@ FUNCTION(("dir: (%Lu)\n", node->GetID()));
RETURN_ERROR(error);
}
// ramfs_close_dir
static status_t
ramfs_close_dir(fs_volume /*fs*/, fs_vnode DARG(_node), fs_cookie _cookie)
@ -1223,6 +1256,7 @@ FUNCTION(("dir: (%Lu)\n", ((Node*)_node)->GetID()));
return B_OK;
}
// ramfs_free_dir_cookie
static status_t
ramfs_free_dir_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
@ -1233,6 +1267,7 @@ ramfs_free_dir_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
return B_OK;
}
// ramfs_read_dir
static status_t
ramfs_read_dir(fs_volume* _volume, fs_vnode DARG(_node), fs_cookie _cookie,
@ -1269,13 +1304,16 @@ PRINT((" entry: `%s'\n", name));
}
} else
*count = 0;
cookie->Suspend();
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rewind_dir
static status_t
ramfs_rewind_dir(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
@ -1324,6 +1362,7 @@ ramfs_open_attr_dir(fs_volume* _volume, fs_vnode _node, fs_cookie *cookie)
RETURN_ERROR(error);
}
// ramfs_close_attr_dir
static status_t
ramfs_close_attr_dir(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie cookie)
@ -1336,6 +1375,7 @@ ramfs_close_attr_dir(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie cookie)
return B_OK;
}
// ramfs_free_attr_dir_cookie
static status_t
ramfs_free_attr_dir_cookie(fs_volume /*fs*/, fs_vnode /*_node*/,
@ -1349,6 +1389,7 @@ ramfs_free_attr_dir_cookie(fs_volume /*fs*/, fs_vnode /*_node*/,
return B_OK;
}
// ramfs_read_attr_dir
static status_t
ramfs_read_attr_dir(fs_volume* _volume, fs_vnode _node, fs_cookie cookie,
@ -1382,13 +1423,16 @@ ramfs_read_attr_dir(fs_volume* _volume, fs_vnode _node, fs_cookie cookie,
}
} else
*count = 0;
iterator->Suspend();
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rewind_attr_dir
static status_t
ramfs_rewind_attr_dir(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie cookie)
@ -1443,10 +1487,11 @@ private:
bigtime_t fLastNotificationTime;
};
// ramfs_create_attr
static status_t
ramfs_create_attr(fs_volume* _volume, fs_vnode _node, const char *name, uint32 type,
int openMode, fs_cookie *_cookie)
ramfs_create_attr(fs_volume* _volume, fs_vnode _node, const char *name,
uint32 type, int openMode, fs_cookie *_cookie)
{
Volume* volume = (Volume*)_volume->private_volume;
@ -1513,10 +1558,11 @@ ramfs_create_attr(fs_volume* _volume, fs_vnode _node, const char *name, uint32 t
return B_OK;
}
// ramfs_open_attr
static status_t
ramfs_open_attr(fs_volume* _volume, fs_vnode _node, const char *name, int openMode,
fs_cookie *_cookie)
ramfs_open_attr(fs_volume* _volume, fs_vnode _node, const char *name,
int openMode, fs_cookie *_cookie)
{
// FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
@ -1572,6 +1618,7 @@ ramfs_open_attr(fs_volume* _volume, fs_vnode _node, const char *name, int openMo
RETURN_ERROR(error);
}
// ramfs_close_attr
static status_t
ramfs_close_attr(fs_volume* _volume, fs_vnode _node, fs_cookie cookie)
@ -1592,6 +1639,7 @@ ramfs_close_attr(fs_volume* _volume, fs_vnode _node, fs_cookie cookie)
}
// ramfs_free_attr_cookie
static status_t
ramfs_free_attr_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
@ -1602,6 +1650,7 @@ ramfs_free_attr_cookie(fs_volume /*fs*/, fs_vnode /*_node*/, fs_cookie _cookie)
return B_OK;
}
// ramfs_read_attr
static status_t
ramfs_read_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
@ -1632,10 +1681,11 @@ ramfs_read_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos
RETURN_ERROR(error);
}
// ramfs_write_attr
static status_t
ramfs_write_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t pos,
const void *buffer, size_t *bufferSize)
ramfs_write_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie,
off_t pos, const void *buffer, size_t *bufferSize)
{
// FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
@ -1647,7 +1697,8 @@ ramfs_write_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t po
const char *name = cookie->GetName();
if (name[0] == '\0' || !strcmp(name, "name")
|| !strcmp(name, "last_modified") || !strcmp(name, "size")) {
//FUNCTION(("failed: node: %s, attribute: %s\n", node->GetName(), name));
// FUNCTION(("failed: node: %s, attribute: %s\n",
// node->GetName(), name));
RETURN_ERROR(B_NOT_ALLOWED);
}
@ -1675,9 +1726,11 @@ ramfs_write_attr(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie, off_t po
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_read_attr_stat
static status_t
ramfs_read_attr_stat(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie,
@ -1710,15 +1763,17 @@ ramfs_read_attr_stat(fs_volume* _volume, fs_vnode _node, fs_cookie _cookie,
RETURN_ERROR(error);
}
// ramfs_rename_attr
static status_t
ramfs_rename_attr(fs_volume /*fs*/, fs_vnode /*_fromNode*/,
const char */*fromName*/, fs_vnode /*_toNode*/, const char */*toName*/)
{
// TODO:...
// TODO : ramfs_rename_attr
return B_BAD_VALUE;
}
// ramfs_remove_attr
static status_t
ramfs_remove_attr(fs_volume* _volume, fs_vnode _node, const char *name)
@ -1751,6 +1806,7 @@ ramfs_remove_attr(fs_volume* _volume, fs_vnode _node, const char *name)
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
@ -1766,6 +1822,7 @@ public:
int32 index_index;
};
// ramfs_open_index_dir
static status_t
ramfs_open_index_dir(fs_volume* _volume, fs_cookie *_cookie)
@ -1788,6 +1845,7 @@ ramfs_open_index_dir(fs_volume* _volume, fs_cookie *_cookie)
RETURN_ERROR(error);
}
// ramfs_close_index_dir
static status_t
ramfs_close_index_dir(fs_volume /*fs*/, fs_cookie /*_cookie*/)
@ -1796,6 +1854,7 @@ ramfs_close_index_dir(fs_volume /*fs*/, fs_cookie /*_cookie*/)
return B_OK;
}
// ramfs_free_index_dir_cookie
static status_t
ramfs_free_index_dir_cookie(fs_volume /*fs*/, fs_cookie _cookie)
@ -1806,10 +1865,11 @@ ramfs_free_index_dir_cookie(fs_volume /*fs*/, fs_cookie _cookie)
return B_OK;
}
// ramfs_read_index_dir
static status_t
ramfs_read_index_dir(fs_volume* _volume, fs_cookie _cookie, struct dirent *buffer,
size_t bufferSize, uint32 *count)
ramfs_read_index_dir(fs_volume* _volume, fs_cookie _cookie,
struct dirent *buffer, size_t bufferSize, uint32 *count)
{
FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
@ -1840,9 +1900,11 @@ ramfs_read_index_dir(fs_volume* _volume, fs_cookie _cookie, struct dirent *buffe
*count = 0;
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rewind_index_dir
static status_t
ramfs_rewind_index_dir(fs_volume /*fs*/, fs_cookie _cookie)
@ -1853,6 +1915,7 @@ ramfs_rewind_index_dir(fs_volume /*fs*/, fs_cookie _cookie)
return B_OK;
}
// ramfs_create_index
static status_t
ramfs_create_index(fs_volume* _volume, const char *name, uint32 type,
@ -1880,9 +1943,11 @@ ramfs_create_index(fs_volume* _volume, const char *name, uint32 type,
SET_ERROR(error, B_ENTRY_NOT_FOUND);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_remove_index
static status_t
ramfs_remove_index(fs_volume* _volume, const char *name)
@ -1912,6 +1977,7 @@ ramfs_remove_index(fs_volume* _volume, const char *name)
RETURN_ERROR(error);
}
// ramfs_read_index_stat
static status_t
ramfs_read_index_stat(fs_volume* _volume, const char *name, struct stat *st)
@ -1955,7 +2021,8 @@ ramfs_open_query(fs_volume* _volume, const char *queryString, uint32 flags,
port_id port, uint32 token, fs_cookie *cookie)
{
FUNCTION_START();
PRINT(("query = \"%s\", flags = %lu, port_id = %ld, token = %ld\n", queryString, flags, port, token));
PRINT(("query = \"%s\", flags = %lu, port_id = %ld, token = %ld\n",
queryString, flags, port, token));
Volume* volume = (Volume*)_volume->private_volume;
@ -1992,6 +2059,7 @@ ramfs_open_query(fs_volume* _volume, const char *queryString, uint32 flags,
return B_OK;
}
// ramfs_close_query
static status_t
ramfs_close_query(fs_volume /*fs*/, fs_cookie /*cookie*/)
@ -2000,6 +2068,7 @@ ramfs_close_query(fs_volume /*fs*/, fs_cookie /*cookie*/)
return B_OK;
}
// ramfs_free_query_cookie
static status_t
ramfs_free_query_cookie(fs_volume* _volume, fs_cookie cookie)
@ -2021,6 +2090,7 @@ ramfs_free_query_cookie(fs_volume* _volume, fs_cookie cookie)
return B_OK;
}
// ramfs_read_query
static status_t
ramfs_read_query(fs_volume* _volume, fs_cookie cookie, struct dirent *buffer,
@ -2046,6 +2116,7 @@ ramfs_read_query(fs_volume* _volume, fs_cookie cookie, struct dirent *buffer,
return B_OK;
}
// TODO: status_t (*rewind_query)(fs_volume fs, fs_cookie cookie);
@ -2073,6 +2144,7 @@ ramfs_std_ops(int32 op, ...)
}
}
static file_system_module_info sRamFSModuleInfo = {
{
"file_systems/ramfs" B_CURRENT_FS_API_VERSION,
@ -2188,3 +2260,4 @@ module_info *modules[] = {
(module_info *)&sRamFSModuleInfo,
NULL,
};