aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 22:35:07 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 22:35:07 +0100
commit9004213b4422e7a43c8ec8aac99d4ecc92553f20 (patch)
tree2e98e49e582494ce2f514fb388fa351637e5dffc /src/common
parent862b93742237ed959e9b8dc12a536880ea45d0cf (diff)
downloadkogata-9004213b4422e7a43c8ec8aac99d4ecc92553f20.tar.gz
kogata-9004213b4422e7a43c8ec8aac99d4ecc92553f20.zip
Begin implementation of nullfs.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/include/fs.h6
-rw-r--r--src/common/include/mutex.h3
-rw-r--r--src/common/mutex.c6
-rw-r--r--src/common/string.c2
4 files changed, 12 insertions, 5 deletions
diff --git a/src/common/include/fs.h b/src/common/include/fs.h
index 2ab0760..1ee3d5e 100644
--- a/src/common/include/fs.h
+++ b/src/common/include/fs.h
@@ -11,6 +11,8 @@
#define FT_FIFO (0x10)
// #define FT_SOCKET (0x20) // Not yet! Semantics not defined. (TODO)
+// FM_* enum describes modes for opening a file as well as authorized operations in stat_t
+// (some flags are used only for open() or only in stat_t.access)
#define FM_READ (0x01)
#define FM_WRITE (0x02)
#define FM_READDIR (0x04)
@@ -18,6 +20,9 @@
#define FM_CREATE (0x10)
#define FM_TRUNC (0x20)
#define FM_APPEND (0x40)
+#define FM_DCREATE (0x100) // create file in directory
+#define FM_DMOVE (0x200) // move file from directory
+#define FM_DUNLINK (0x400) // delete file from directory
typedef struct {
int type;
@@ -30,6 +35,7 @@ typedef struct {
typedef struct {
char name[DIR_MAX];
+ stat_t st;
} dirent_t;
diff --git a/src/common/include/mutex.h b/src/common/include/mutex.h
index 6814adf..88c077e 100644
--- a/src/common/include/mutex.h
+++ b/src/common/include/mutex.h
@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
+#include <stdbool.h>
#define MUTEX_LOCKED 1
#define MUTEX_UNLOCKED 0
@@ -9,7 +10,7 @@
typedef uint32_t mutex_t;
void mutex_lock(mutex_t* mutex); //wait for mutex to be free
-int mutex_try_lock(mutex_t* mutex); //lock mutex only if free, returns !0 if locked, 0 if was busy
+bool mutex_try_lock(mutex_t* mutex); //lock mutex only if free, returns true when locked, false when was busy
void mutex_unlock(mutex_t* mutex);
// the mutex code assumes a yield() function is defined somewhere
diff --git a/src/common/mutex.c b/src/common/mutex.c
index cda8049..b345ee5 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -13,11 +13,11 @@ void mutex_lock(uint32_t* mutex) {
}
}
-int mutex_try_lock(uint32_t* mutex) {
+bool mutex_try_lock(uint32_t* mutex) {
if (atomic_exchange(mutex, MUTEX_LOCKED) == MUTEX_LOCKED) {
- return 0;
+ return false;
}
- return 1;
+ return true;
}
void mutex_unlock(uint32_t* mutex) {
diff --git a/src/common/string.c b/src/common/string.c
index b50356a..f6c27b4 100644
--- a/src/common/string.c
+++ b/src/common/string.c
@@ -57,7 +57,7 @@ int strcmp(const char *s1, const char *s2) {
return (*(unsigned char*)s1 - *(unsigned char*)s2);
}
-int strcmp(const char *s1, const char *s2, size_t n) {
+int strncmp(const char *s1, const char *s2, size_t n) {
size_t i = 0;
while ((*s1) && (*s1 == *s2) && i != n) {
s1++;