Commit f7e7b624 authored by Kevin Wolf's avatar Kevin Wolf

kernel2: Fehlercodes zurückgeben in lio_mkfile/dir/symlink

* kernel2: lio_mkfile/dir/symlink können jetzt einen Fehlercode
  zurückgeben statt nur NULL (woraus immer -EIO wurde)

+ kernel2: EEXIST zurückgeben, wenn lio_mkfile/dir/symlink mit einem
  Dateinamen aufgerufen wird, den es im Verzeichnis schon gibt
Signed-off-by: Kevin Wolf's avatarKevin Wolf <kevin@tyndur.org>
parent 72fed816
......@@ -172,14 +172,16 @@ ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num,
struct lio_dir_entry* buf);
/** Erstellt eine neue Datei */
struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name);
int lio_mkfile(struct lio_resource* parent, const char* name,
struct lio_resource** res);
/** Erstellt ein neues Verzeichnis */
struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name);
int lio_mkdir(struct lio_resource* parent, const char* name,
struct lio_resource** res);
/** Erstellt einen neuen Symlink */
struct lio_resource* lio_mksymlink(struct lio_resource* parent,
const char* name, const char* target);
int lio_mksymlink(struct lio_resource* parent, const char* name,
const char* target, struct lio_resource** res);
/**
* Gibt Informationen zu einer Ressource zurueck
......
......@@ -132,7 +132,9 @@ static int get_node_in_dir(struct lio_resource* dir, const char* name,
// Passendes Kind raussuchen
for (i = 0; (n = list_get_element_at(dir->children, i)); i++) {
if (strcmp(n->name, name) == 0) {
*node = n;
if (node) {
*node = n;
}
return 0;
}
}
......@@ -708,34 +710,51 @@ ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num,
}
/** Erstellt eine neue Datei */
struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name)
int lio_mkfile(struct lio_resource* parent, const char* name,
struct lio_resource** res)
{
if (!parent->tree->service->lio_ops.make_file || !parent->changeable) {
return NULL;
return -EACCES;
}
return parent->tree->service->lio_ops.make_file(parent, name);
if (get_node_in_dir(parent, name, NULL) == 0) {
return -EEXIST;
}
*res = parent->tree->service->lio_ops.make_file(parent, name);
return *res ? 0 : -EIO;
}
/** Erstellt ein neues Verzeichnis */
struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name)
int lio_mkdir(struct lio_resource* parent, const char* name,
struct lio_resource** res)
{
if (!parent->tree->service->lio_ops.make_dir || !parent->changeable) {
return NULL;
return -EACCES;
}
return parent->tree->service->lio_ops.make_dir(parent, name);
if (get_node_in_dir(parent, name, NULL) == 0) {
return -EEXIST;
}
*res = parent->tree->service->lio_ops.make_dir(parent, name);
return *res ? 0 : -EIO;
}
/** Erstellt einen neuen Symlink */
struct lio_resource* lio_mksymlink(struct lio_resource* parent,
const char* name, const char* target)
int lio_mksymlink(struct lio_resource* parent, const char* name,
const char* target, struct lio_resource** res)
{
if (!parent->tree->service->lio_ops.make_symlink || !parent->changeable) {
return NULL;
return -EACCES;
}
if (get_node_in_dir(parent, name, NULL) == 0) {
return -EEXIST;
}
return parent->tree->service->lio_ops.make_symlink(parent, name, target);
*res = parent->tree->service->lio_ops.make_symlink(parent, name, target);
return *res ? 0 : -EIO;
}
/**
......
......@@ -255,6 +255,7 @@ void lio_init_tmp(void)
lio_add_service(&dev_service);
dev_root = lio_get_resource("dev:/", false);
if (dev_root != NULL) {
lio_mkdir(dev_root, "fs");
struct lio_resource* dev_fs_res;
lio_mkdir(dev_root, "fs", &dev_fs_res);
}
}
......@@ -293,6 +293,7 @@ void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
{
struct lio_resource* parentres;
struct lio_resource* res;
int ret;
parentres = lio_usp_get_resource(*parent);
if (parentres == NULL) {
......@@ -307,9 +308,9 @@ void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
}
// TODO: is_userspace
res = lio_mkfile(parentres, name);
if (res == NULL) {
*result = -EIO; // FIXME
ret = lio_mkfile(parentres, name, &res);
if (ret < 0) {
*result = ret;
return;
}
......@@ -322,6 +323,7 @@ void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
{
struct lio_resource* parentres;
struct lio_resource* res;
int ret;
parentres = lio_usp_get_resource(*parent);
if (parentres == NULL) {
......@@ -336,9 +338,9 @@ void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
}
// TODO: is_userspace
res = lio_mkdir(parentres, name);
if (res == NULL) {
*result = -EIO; // FIXME
ret = lio_mkdir(parentres, name, &res);
if (ret < 0) {
*result = ret;
return;
}
......@@ -352,6 +354,7 @@ void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
{
struct lio_resource* parentres;
struct lio_resource* res;
int ret;
parentres = lio_usp_get_resource(*parent);
if (parentres == NULL) {
......@@ -371,9 +374,9 @@ void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
return;
}
res = lio_mksymlink(parentres, name, target);
if (res == NULL) {
*result = -EIO; // FIXME
ret = lio_mksymlink(parentres, name, target, &res);
if (ret < 0) {
*result = ret;
return;
}
*result = lio_usp_get_id(res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment