- change close(node) in close(file)
- disable close in netchar, for testing
This commit is contained in:
parent
36de5701ce
commit
2f89686df8
8 changed files with 33 additions and 38 deletions
|
@ -44,7 +44,7 @@ static int null_open(fildes_t* file, const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int null_close(vfs_node_t* node)
|
||||
static int null_close(fildes_t* file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
#include <metalsvm/errno.h>
|
||||
#include <metalsvm/fs.h>
|
||||
#include <metalsvm/spinlock.h>
|
||||
#include <lwip/opt.h>
|
||||
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#include <lwip/mem.h>
|
||||
#include <lwip/raw.h>
|
||||
#include <lwip/icmp.h>
|
||||
|
@ -36,36 +37,32 @@
|
|||
#include <lwip/sockets.h>
|
||||
#include <lwip/inet.h>
|
||||
#include <lwip/err.h>
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Implementation of a simple stdout device */
|
||||
|
||||
static ssize_t netchar_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
//kprintf("\nlwip_read: %p with lenght %i and Socket %i", buffer, size, file->offset);
|
||||
|
||||
int ret;
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
int ret = 0;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
ret = lwip_read((int)file->offset, buffer, size);
|
||||
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
//#else
|
||||
//#endif
|
||||
#endif
|
||||
kprintf("return size: %i", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t netchar_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
int ret;
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
int ret = 0;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
ret = lwip_write(file->offset, buffer, size);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
//#else
|
||||
//#endif
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -74,16 +71,14 @@ static int netchar_open(fildes_t* file, const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int netchar_close(vfs_node_t* node) //////////////change this in File!!!
|
||||
static int netchar_close(fildes_t* file)
|
||||
{
|
||||
int ret;
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
// ret = lwip_close(file->offset);
|
||||
int ret = 0;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
//ret = lwip_close(file->offset);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
//#else
|
||||
ret = 0;
|
||||
//#endif
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static int stderr_open(fildes_t* file, const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int stderr_close(vfs_node_t* node)
|
||||
static int stderr_close(fildes_t* file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ static int stdin_open(fildes_t* file, const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int stdin_close(vfs_node_t* node)
|
||||
static int stdin_close(fildes_t* file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ static int stdout_open(fildes_t* file, const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int stdout_close(vfs_node_t* node)
|
||||
static int stdout_close(fildes_t* file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
12
fs/fs.c
12
fs/fs.c
|
@ -105,18 +105,18 @@ int open_fs(fildes_t* file, const char* name)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int close_fs(vfs_node_t* node)
|
||||
int close_fs(fildes_t* file)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (BUILTIN_EXPECT(!node, 0))
|
||||
if (BUILTIN_EXPECT(!(file->node), 0))
|
||||
return ret;
|
||||
|
||||
spinlock_lock(&node->lock);
|
||||
spinlock_lock(&file->node->lock);
|
||||
// Has the node got a close callback?
|
||||
if (node->close != 0)
|
||||
ret = node->close(node);
|
||||
spinlock_unlock(&node->lock);
|
||||
if (file->node->close != 0)
|
||||
ret = file->node->close(file);
|
||||
spinlock_unlock(&file->node->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ typedef ssize_t (*write_type_t) (struct fildes *, uint8_t*, size_t);
|
|||
/** @brief Open function pointer */
|
||||
typedef int (*open_type_t) (struct fildes *, const char *name);
|
||||
/** @brief Close function pointer */
|
||||
typedef int (*close_type_t) (struct vfs_node *);
|
||||
typedef int (*close_type_t) (struct fildes *);
|
||||
/** @brief Read directory function pointer */
|
||||
typedef struct dirent *(*readdir_type_t) (struct vfs_node *, uint32_t);
|
||||
/** @brief Find directory function pointer */
|
||||
|
@ -202,7 +202,7 @@ ssize_t write_fs(fildes_t* file, uint8_t* buffer, size_t size);
|
|||
/** @brief Yet to be documented */
|
||||
int open_fs(fildes_t* file, const char* fname);
|
||||
/** @brief Yet to be documented */
|
||||
int close_fs(vfs_node_t * node);
|
||||
int close_fs(fildes_t * file);
|
||||
|
||||
/** @brief Get dir entry at index
|
||||
* @param node VFS node to get dir entry from
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <metalsvm/time.h>
|
||||
#include <lwip/opt.h>
|
||||
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#include <lwip/mem.h>
|
||||
#include <lwip/raw.h>
|
||||
#include <lwip/icmp.h>
|
||||
|
@ -40,7 +40,7 @@
|
|||
#include <lwip/inet.h>
|
||||
#include <lwip/err.h>
|
||||
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
static int sys_open(const char* name, int flags, int mode)
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ static int sys_open(const char* name, int flags, int mode)
|
|||
return fd;
|
||||
}
|
||||
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
static int sys_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int fd;
|
||||
|
@ -114,13 +114,13 @@ static int sys_accept(int s, struct sockaddr* addr, socklen_t* addrlen)
|
|||
return fd;
|
||||
}
|
||||
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
|
||||
static int sys_close(int fd)
|
||||
{
|
||||
fildes_t* file = &(per_core(current_task)->fildes_table[fd]);
|
||||
close_fs(file->node);
|
||||
close_fs(file);
|
||||
file->node = NULL;
|
||||
file->offset = 0;
|
||||
file->mode = 0;
|
||||
|
@ -275,7 +275,7 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
ret = sys_times(buffer, clock);
|
||||
break;
|
||||
}
|
||||
//#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
case __NR_closesocket: {
|
||||
int fd = va_arg(vl, int);
|
||||
|
||||
|
@ -356,7 +356,7 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
ret = -errno;
|
||||
break;
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
default:
|
||||
kputs("invalid system call\n");
|
||||
ret = -ENOSYS;
|
||||
|
|
Loading…
Add table
Reference in a new issue