Started trying to get the syscall forwading stuff working between BOCHS and my native...
authorROS Developer <ros-dev@core0.(none)>
Sat, 26 Sep 2009 02:30:38 +0000 (04:30 +0200)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 1 Oct 2009 20:09:51 +0000 (22:09 +0200)
18 files changed:
.gitignore
kern/src/manager.c
kern/src/syscall.c
tools/syscall_server.c [deleted file]
tools/syscall_server.h [deleted file]
tools/syscall_server/.ros_slave_pty [new file with mode: 0644]
tools/syscall_server/Makefile [new file with mode: 0644]
tools/syscall_server/newlib_stat.h [new file with mode: 0644]
tools/syscall_server/syscall_server.c [new file with mode: 0644]
tools/syscall_server/syscall_server.h [new file with mode: 0644]
tools/syscall_server/test/input [new file with mode: 0644]
tools/syscall_server/translate_state.c [new file with mode: 0644]
user/parlib/inc/newlib_backend.h
user/parlib/newlib/include/sys/stat.h
user/parlib/newlib/lib/i386/libc.a
user/parlib/newlib/lib/i386/libg.a
user/parlib/newlib/lib/i386/libm.a
user/parlib/src/i386/newlib_backend.c

index 2861b4c..229eaac 100644 (file)
@@ -21,4 +21,5 @@ kern/boot
 kern/include/arch
 kern/src/arch
 doc/rosdoc
-
+sim/
+tools/.*
index a331580..8639de2 100644 (file)
@@ -37,14 +37,14 @@ void manager(void)
        // This is a bypass of the standard manager structure, for network use
        // If enabled, this spawns parlib_matrix, and allows the execution
        // of a remote binary to function correctly (schedule() call below)
-       #ifdef __NETWORK__      
+       //#ifdef __NETWORK__    
        if (progress++ == 0) {
                envs[0] = kfs_proc_create(kfs_lookup_path("parlib_matrix"));
                proc_set_state(envs[0], PROC_RUNNABLE_S);
                proc_run(envs[0]);
        }
        schedule();
-       #endif 
+       //#endif 
 
        switch (progress++) {
                case 0:
index 85821f8..c24afca 100644 (file)
@@ -38,6 +38,8 @@ static void sys_null(void)
 //Write a buffer over the serial port
 static ssize_t sys_serial_write(env_t* e, const char *DANGEROUS buf, size_t len)
 {
+       if (len == 0)
+               return 0;
        #ifdef SERIAL_IO
                char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_USER_RO);
                for(int i =0; i<len; i++)
@@ -51,6 +53,9 @@ static ssize_t sys_serial_write(env_t* e, const char *DANGEROUS buf, size_t len)
 //Read a buffer over the serial port
 static ssize_t sys_serial_read(env_t* e, char *DANGEROUS _buf, size_t len)
 {
+       if (len == 0)
+               return 0;
+
        #ifdef SERIAL_IO
            char *COUNT(len) buf = user_mem_assert(e, _buf, len, PTE_USER_RO);
                size_t bytes_read = 0;
@@ -494,15 +499,15 @@ intreg_t syscall(env_t* e, uintreg_t syscallno, uintreg_t a1, uintreg_t a2,
                        return sys_serial_write(e, (char *DANGEROUS)a1, (size_t)a2);
                case SYS_serial_read:
                        return sys_serial_read(e, (char *DANGEROUS)a1, (size_t)a2);
-                case SYS_run_binary:
-                        return sys_run_binary(e, (char *DANGEROUS)a1,
-                                              (char* DANGEROUS)a2, (size_t)a3);
+               case SYS_run_binary:
+                       return sys_run_binary(e, (char *DANGEROUS)a1,
+                                             (char* DANGEROUS)a2, (size_t)a3);
        #endif
        #ifdef __NETWORK__
-                case SYS_eth_write:
-                        return sys_eth_write(e, (char *DANGEROUS)a1, (size_t)a2);
-                case SYS_eth_read:
-                        return sys_eth_read(e, (char *DANGEROUS)a1, (size_t)a2);
+               case SYS_eth_write:
+                       return sys_eth_write(e, (char *DANGEROUS)a1, (size_t)a2);
+               case SYS_eth_read:
+                       return sys_eth_read(e, (char *DANGEROUS)a1, (size_t)a2);
        #endif
        #ifdef __sparc_v8__
                case SYS_frontend:
diff --git a/tools/syscall_server.c b/tools/syscall_server.c
deleted file mode 100644 (file)
index f584eb8..0000000
+++ /dev/null
@@ -1,656 +0,0 @@
-#include "syscall_server.h"
-#include <sys/ioctl.h>
-#include <termios.h>
-
-/* Remote Syscall Server app. 
-   Written by Paul Pearce.
-   This is an UGLY HACK to avoid sockets to work with the 
-   ugly hack that is the current tesselaton udp wrapping.
-
-   If you search for the comment UDP you can see how to revert this back
-   to socket niceness.
-
-   Note: The server.h has a shared structure with the newlib_backend.h. These must be kept in sync
-         The only difference is Paul's GCC won't allow unions without names, so the 'subheader' name was added
-*/
-
-// UDP BRANCH
-#include <netdb.h>
-char udp_arr[4096];
-int udp_arr_size = 0;
-int udp_cur_pos = 0;
-// END UDP BRANCH
-
-// TODO: A syscall_id_t that says close the link, and deal with that in the main switch statement.
-int main()
-{
-       // Listen for connections.
-       int data_port = listen_for_connections();
-
-       // Once here, we are inside of new processes, setup the new port.
-       int data_fd = setup_data_connection(data_port);
-
-       // Begin processing data from the connection
-       process_connections(data_fd);
-}
-
-// Bind to LISTEN_PORT and listen for connections on the specified port.
-// If a client requests a connection, spawn off a new process, then continue.
-// In new process, return with the port we are going to listen for data on
-int listen_for_connections()
-{
-       //UDP BRANCH. Do nothing, as this is UDP
-       return -1;
-       // END UDP BRANCH
-
-       // Sockets
-       int listen_socket, data_socket;
-
-       // Address structures
-       struct sockaddr_in server_addr, client_addr;
-
-       // Self explanatory
-       int num_connections, response_msg;
-
-       // Size of our address structure
-       unsigned int addr_len = sizeof(struct sockaddr_in);
-
-       // Fork response for determining if child or parent
-       int child;
-
-       // Create socket
-       if ((listen_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
-       {
-               printf("Error: Could not create socket.\n");
-               exit(1);
-       }
-
-       // Setup sockaddr_in
-       server_addr.sin_family = AF_INET;
-       server_addr.sin_port = htons(LISTEN_PORT);
-       server_addr.sin_addr.s_addr = INADDR_ANY;
-       bzero(&(server_addr.sin_zero), 8);      // This is apparently a source of bugs? Who knew.
-
-       // Bind to the given port.
-       if (bind(listen_socket, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)))
-       {
-               printf("Error: Could not bind to port: %i\n", LISTEN_PORT);
-               exit(1);
-       }
-
-       // Listen on the socket
-    if (listen(listen_socket, BACKLOG_LEN) < 0)
-    {
-       printf("Error: Could not listen on socket.\n");
-       exit(1);
-    }
-
-       printf("Server started.\n");
-
-       // Main loop to listen for connections.
-       while(1)
-       {
-               printf("Waiting for connections on port: %i\n", LISTEN_PORT);
-
-               if ((data_socket = accept(listen_socket, (struct sockaddr *)&client_addr,  &addr_len)) < 0)
-               {
-                       printf("Error: Could not accept a new connection.\n");
-               }
-
-               num_connections++;
-               response_msg = num_connections + LISTEN_PORT;
-
-               printf("New connection detected. Assigning port: %i\n", response_msg);
-               if (send(data_socket, (char*)(&response_msg), sizeof(int), 0) < 0)
-               {
-                       printf("Error: Could not send response. New client may not have received port. Continuing.\n");
-                       close(data_socket);
-                       continue;
-               }
-               close(data_socket);
-
-               // Spawn a new process for the connection and offload further communications to that process.
-               if ((child = fork()) == -1)
-               {
-                       printf("Error: Fork failed. Client responses will be ignored. Continuing.\n");
-                       continue;
-               }
-               else if (child)
-               {
-                       // Spawned Process, break out of loop for cleanup and initialization of the listen function.
-                       break;
-               }
-               else
-               {
-                       // Original Process
-                       // Nothing to do. Continue loop.
-               }
-       }
-
-       // Only reach here inside of new process, after spawning. Clean up.
-       close(listen_socket);
-
-       return response_msg;
-}
-
-
-// Perform socket setup on the new port
-int setup_data_connection(int port)
-{
-       // UDP BRANCH
-       port = 44444;
-       // END UDP BRANCH
-
-       // Sockets
-       int listen_socket, data_socket;
-
-       // Address structures
-       struct sockaddr_in server_addr, client_addr;
-
-       // Size of our address structure
-       unsigned int addr_len = sizeof(struct sockaddr_in);
-
-       // Create socket
-       // UDP BRANCH
-       // if ((listen_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
-       if ((listen_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
-       {
-               printf("Error: Spawned Process, PORT: %i. Could not create socket.\n", port);
-               exit(1);
-       }
-
-       // Setup sockaddr_in
-       server_addr.sin_family = AF_INET;
-       server_addr.sin_port = htons(port);
-       server_addr.sin_addr.s_addr=INADDR_ANY;
-       bzero(&(server_addr.sin_zero), 8);      // This is apparently a source of bugs? Who knew.
-
-       // Bind to the given port.
-       if (bind(listen_socket, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)))
-       {
-               printf("Error: Spawned Process, PORT: %i. Could not bind to port.\n", port);
-               exit(1);
-       }
-
-       //UDP BRANCH
-       data_socket = listen_socket;
-
-       // UDP BRANCH COMMENTED
-       /*
-
-       // Listen on the socket
-    if (listen(listen_socket, BACKLOG_LEN) < 0)
-    {
-       printf("Error: Spawned Process, PORT: %i. Could not listen on socket.\n", port);
-       exit(1);
-    }
-
-       if ((data_socket = accept(listen_socket, (struct sockaddr *)&client_addr,  &addr_len)) < 0)
-       {
-               printf("Error:  Spawned Process, PORT: %i. Could not accept a new connection.\n", port);
-       }
-
-       */ // UDP BRANCH END COMMENT
-
-       printf("Spawned Process, PORT: %i. FD: %i. Established.\n", port, data_socket);
-
-       // END SOCKET SETUP
-
-       return data_socket;
-}
-
-// Poll for a message, return a pointer to message. Caller is required to manage memory of the buffer
-// Called by the server to get data
-void process_connections(int fd) {
-
-       // Variables for the fixed filds.
-       syscall_id_t id;
-
-       int just_read;
-       
-       msg_t temp_msg;
-
-       // TODO: Better msg cleanup on close. Channel cleanup in general
-       while(1)
-       {
-               // Read data from the socket.
-               // Peek == 1, thus if no data is avaiable, return. Else, wait until full syscall_id_t is avaiable
-               just_read = read_header_from_socket(&temp_msg, fd);
-
-               if (just_read == 0)
-               {
-                       //sleep(1);
-                       continue;
-               }
-               
-               id = temp_msg.id;
-
-               // If we couldnt read data, or the ID we got is bad, terminate process.
-               if ((just_read == -1) || (id < 0) || (id > NUM_CALLS))
-               {
-                       printf("error on id: %d\n", id);
-                       send_error(fd);
-
-                       return;
-               }
-
-               msg_t * msg = NULL;
-               response_t * return_msg = NULL;
-               int return_len = -1;
-
-               switch (id) {
-                       case OPEN_ID:
-                               msg = malloc(sizeof(msg_t) + temp_msg.subheader.open.len);
-                               if (msg == NULL) {
-                                       send_error(fd);
-                                       return;
-                               }
-                               
-                               *msg = temp_msg;
-                               just_read = read_buffer_from_socket(msg->subheader.open.buf, fd, msg->subheader.open.len);
-                               
-                               if (just_read != msg->subheader.open.len) {
-                                       free(msg);
-                                       send_error(fd);
-                                       return;
-                               }
-
-                               return_msg = handle_open(msg);
-                               free(msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case CLOSE_ID:
-                               return_msg = handle_close(&temp_msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case READ_ID:
-                               return_msg = handle_read(&temp_msg);
-                               if (return_msg != NULL)
-                                       return_len = sizeof(response_t) + ((return_msg->ret >= 0)  ? return_msg->ret : 0);
-                               break;
-
-                       case WRITE_ID:
-
-                               msg = malloc(sizeof(msg_t) + temp_msg.subheader.write.len);
-                               if (msg == NULL) {
-                                       send_error(fd);
-                                       return;
-                               }
-                               
-                               *msg = temp_msg;
-                               just_read = read_buffer_from_socket(msg->subheader.write.buf, fd, msg->subheader.write.len);
-
-                               if (just_read != msg->subheader.write.len) {
-                                       free(msg);
-                                       send_error(fd);
-                                       return;
-                               }
-
-                               return_msg = handle_write(msg);
-                               free(msg);
-
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case LSEEK_ID:
-
-                               return_msg = handle_lseek(&temp_msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case ISATTY_ID:
-                               return_msg = handle_isatty(&temp_msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case UNLINK_ID:
-                               msg = malloc(sizeof(msg_t) + temp_msg.subheader.unlink.len);
-                               if (msg == NULL) {
-                                       send_error(fd);
-                                       return;
-                               }
-                               
-                               *msg = temp_msg;
-                               just_read = read_buffer_from_socket(msg->subheader.unlink.buf, fd, msg->subheader.unlink.len);
-                               
-                               if (just_read != msg->subheader.unlink.len) {
-                                       free(msg);
-                                       send_error(fd);
-                                       return;
-                               }
-                       
-                               return_msg = handle_unlink(msg);
-                               free(msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case LINK_ID:
-                       
-                               msg = malloc(sizeof(msg_t) + temp_msg.subheader.link.old_len + temp_msg.subheader.link.new_len);
-                               if (msg == NULL) {
-                                       send_error(fd);
-                                       return;
-                               }
-                               
-                               *msg = temp_msg;
-                               just_read = read_buffer_from_socket(msg->subheader.link.buf, fd, temp_msg.subheader.link.old_len + temp_msg.subheader.link.new_len);
-                               
-                               if (just_read != (temp_msg.subheader.link.old_len + temp_msg.subheader.link.new_len)) {
-                                       free(msg);
-                                       send_error(fd);
-                                       return;
-                               }
-                       
-                               return_msg = handle_link(msg);
-                               free(msg);
-                               return_len = sizeof(response_t);
-                               break;
-
-                       case FSTAT_ID:
-                               return_msg = handle_fstat(&temp_msg);
-                               return_len = sizeof(response_t);
-
-                               break;
-
-                       case STAT_ID:
-                               msg = malloc(sizeof(msg_t) + temp_msg.subheader.stat.len);
-                               if (msg == NULL) {
-                                       send_error(fd);
-                                       return;
-                               }
-                       
-                               *msg = temp_msg;
-                               just_read = read_buffer_from_socket(msg->subheader.stat.buf, fd, msg->subheader.stat.len);
-                       
-                               if (just_read != msg->subheader.stat.len) {
-                                       free(msg);
-                                       send_error(fd);
-                                       return;
-                               }
-
-                               return_msg = handle_stat(msg);
-                               free(msg);
-                               return_len = sizeof(response_t);
-
-                               break;
-                       default:
-                               send_error(fd);
-                               return;
-               }
-
-               if (return_msg == NULL)
-               {
-                       send_error(fd);
-                       return;
-               }
-
-               // UDP BRANCH. 
-               struct hostent *hp;
-               hp = gethostbyname("192.168.0.10");
-               struct sockaddr_in addr;
-               memset(&addr, 0, sizeof(addr));
-               addr.sin_family = AF_INET;
-               memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
-               addr.sin_port = htons(44443);
-               // END UDP BRANCH
-
-               if ( sendto(fd, return_msg, return_len, 0, (struct sockaddr *)&addr, sizeof(addr)) != return_len)
-               //if (write(fd, return_msg, return_len) != return_len)
-               {
-                       free(return_msg);
-                       // If we cant write to the socket, cant send CONNECTION_TERMINATED. Just die.
-                       printf("Error: Spawned Process, FD: %i. Could not send data out. Dying.\n", fd);
-                       return;
-               }
-
-               free(return_msg);
-       }
-}
-
-int read_header_from_socket(msg_t* msg, int socket) {
-       return read_from_socket((char*)msg, socket, sizeof(msg_t), PEEK);
-}
-
-int read_buffer_from_socket(char* buf, int socket, int len) {
-       return read_from_socket(buf, socket, len, NO_PEEK);
-}
-
-// UDP HACK VERSION
-// Read len bytes from the given socket to the buffer.
-// If peek is NO_PEEK, will wait indefinitely until that much data is read.
-// If peek is PEEK, if no data is available, will return immediately.
-//             However once some data is available, it will block until the entire amount is available.
-// Return values are:
-// -1 if error
-// 0 if peek and nothing avaiable
-// else len
-int read_from_socket(char* buf, int socket, int len, int peek) {
-
-       // This function is now super hacked to deal with UDP uglyness. Do not use this to revert once we get tcpip online!
-
-       int total_read = 0;
-
-       if (udp_arr_size == 0) {
-               udp_arr_size = recvfrom(socket, udp_arr, 4096, 0, 0, 0);
-
-               if (udp_arr_size == 0)
-                       return -1;
-       }
-
-       if ((udp_cur_pos + len) > udp_arr_size)
-               return -1;
-
-       memcpy(buf, udp_arr + udp_cur_pos, len);
-
-       udp_cur_pos = udp_cur_pos + len;
-
-       if (udp_cur_pos == udp_arr_size) {
-               udp_cur_pos = 0;
-               udp_arr_size = 0;
-       }
-
-       return len;
-
-       // UDP BRANCH
-       //int just_read = read(socket, buf, len);
-       int just_read = recvfrom(socket, buf, len, 0, 0, 0);
-
-       if (just_read < 0) return just_read;
-       if (just_read == 0 && peek) return just_read;
-
-       total_read += just_read;
-
-       while (total_read != len) {
-               // UDP BRANCH
-               //just_read = read(socket, buf + total_read, len - total_read);
-               just_read = recvfrom(socket, buf + total_read, len - total_read, 0, 0, 0);
-
-               if (just_read == -1) return -1;
-
-               total_read += just_read;
-       }
-
-       return total_read;
-}
-
-// Non hacky UDP version
-/*
-int read_from_socket(char* buf, int socket, int len, int peek) {
-        int total_read = 0;
-        //printf("\t\treading %i bytes on socket %i with peek %i\n", len, socket, peek);
-        int just_read = read(socket, buf, len);
-        //printf("\t\tread    %i bytes on socket %i with peek %i\n", just_read, socket, peek);
-                                        
-        if (just_read < 0) return just_read;
-        if (just_read == 0 && peek) return just_read;
-                                
-        total_read += just_read;
-                                
-        while (total_read != len) {
-                just_read = read(socket, buf + total_read, len - total_read);
-                if (just_read == -1) return -1;
-                total_read += just_read;
-        }                       
-                
-        return total_read;
-}*/
-
-
-// Send CONNECTION_TERMINATED over the FD (if possible)
-// Not fully functional.
-void send_error(int fd)
-{
-       printf("Error: Spawned Process, FD: %i. Could not read from from socket. Sending CONNECTION_TERMINATED.... ", fd);
-
-       int error_msg = CONNECTION_TERMINATED;
-
-       /*if (write(fd, (char*)(&error_msg) , sizeof(int)) != sizeof(int))
-       {
-               printf("Could not send CONNECTION_TERMINATED.\n");
-       }
-       else
-       {
-               printf("Sent.\n");
-
-       }*/
-
-       close(fd);
-}
-
-
-response_t* handle_open(msg_t *msg)
-{
-       printf("opening: %s\n", msg->subheader.open.buf);
-       
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-
-       response->ret = open(msg->subheader.open.buf, msg->subheader.open.flags, msg->subheader.open.mode);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_close(msg_t *msg)
-{              
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-
-       response->ret = close(msg->subheader.close.fd);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_read(msg_t * msg) 
-{      
-       response_t * response = malloc(sizeof(response_t) + msg->subheader.read.len);
-       if (response == NULL) return NULL;
-
-       response->ret = read(msg->subheader.read.fd, response->buf, msg->subheader.read.len);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_write(msg_t * msg) 
-{
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-       response->ret = write(msg->subheader.write.fd, msg->subheader.write.buf, msg->subheader.write.len);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_lseek(msg_t * msg)
-{
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-       response->ret = lseek(msg->subheader.lseek.fd, msg->subheader.lseek.ptr, msg->subheader.lseek.dir);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-}
-
-response_t* handle_isatty(msg_t * msg) 
-{
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-       
-       response->ret = isatty(msg->subheader.isatty.fd);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_unlink(msg_t * msg)
-{
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-
-       response->ret = unlink(msg->subheader.unlink.buf);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_link(msg_t * msg) 
-{
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-
-       response->ret = link(msg->subheader.link.buf, msg->subheader.link.buf + msg->subheader.link.old_len);
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_stat(msg_t * msg) {
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-
-       response->ret = stat(msg->subheader.stat.buf, &(response->st));
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
-
-response_t* handle_fstat(msg_t *msg) {
-       
-       response_t * response = malloc(sizeof(response_t));
-       if (response == NULL) return NULL;
-
-       response->ret = fstat(msg->subheader.fstat.fd, &(response->st));
-       
-       if (response->ret == -1) {
-               response->err = errno;
-       }
-
-       return response;
-}
diff --git a/tools/syscall_server.h b/tools/syscall_server.h
deleted file mode 100644 (file)
index 7ff316e..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-// Todo: review the laundry list of includes.
-
-// Backlog for the listen() call.
-#define BACKLOG_LEN 16
-
-#define LISTEN_PORT 12345
-#define SERVER_IP "128.32.35.43"
-
-#define OPEN_ID                0
-#define CLOSE_ID       1
-#define READ_ID                2
-#define WRITE_ID       3
-#define LINK_ID                4
-#define UNLINK_ID      5
-#define LSEEK_ID       6
-#define FSTAT_ID       7
-#define ISATTY_ID      8
-#define STAT_ID                9
-#define NUM_CALLS      10
-
-// New errno we want to define if a channel error occurs
-// Not yet fully implimented
-#define ECHANNEL -999
-
-// Value to send across the channel as a function return value in the event of server side termination
-// Note yet fully implimented
-#define CONNECTION_TERMINATED -2
-
-// Macros for the read_from_channel function
-#define PEEK    1
-#define NO_PEEK 0
-
-// Should refactor this next typedef. Just leave it as type int.
-typedef int syscall_id_t;
-
-// ALL STRUCTS MUST BE PADDED TO THE SAME SIZE.
-// Basically, to make IVY annotation possible with as few TC's as possible
-// We do some ugly things with unions, which results in us needing this padding
-typedef struct open_subheader {
-       uint32_t flags;
-       uint32_t mode;
-       uint32_t len;
-       char buf[0];
-} open_subheader_t;
-
-typedef struct close_subheader {
-       uint32_t fd;
-       uint32_t FILL1;
-       uint32_t FILL2;
-} close_subheader_t;
-
-typedef struct read_subheader {
-       uint32_t fd;
-       uint32_t len;
-       uint32_t FILL1;
-} read_subheader_t;
-
-typedef struct write_subheader {
-       uint32_t fd;
-       uint32_t len;
-       uint32_t FILL1;
-       char buf[0];
-} write_subheader_t;
-
-typedef struct lseek_subheader {
-       uint32_t fd;
-       uint32_t ptr;
-       uint32_t dir;
-} lseek_subheader_t;
-
-typedef struct isatty_subheader {
-       uint32_t fd;
-       uint32_t FILL1;
-       uint32_t FILL2;
-} isatty_subheader_t;
-
-typedef struct link_subheader {
-       uint32_t old_len;
-       uint32_t new_len;
-       uint32_t FILL1;
-       char buf[0];
-} link_subheader_t;
-
-typedef struct unlink_subheader {
-       uint32_t len;
-       uint32_t FILL1;
-       uint32_t FILL2;
-       char buf[0];
-} unlink_subheader_t;
-
-typedef struct fstat_subheader {
-       uint32_t fd;
-       uint32_t FILL1;
-       uint32_t FILL2;
-} fstat_subheader_t;
-
-typedef struct stat_subheader {
-       uint32_t len;
-       uint32_t FILL1;
-       uint32_t FILL2;
-       char buf[0];
-} stat_subheader_t;
-
-typedef struct backend_msg {
-       syscall_id_t id;
-       union {
-               open_subheader_t open;
-               close_subheader_t close;
-               read_subheader_t read;
-               write_subheader_t write;
-               lseek_subheader_t lseek;
-               isatty_subheader_t isatty;
-               link_subheader_t link;
-               unlink_subheader_t unlink;
-               fstat_subheader_t fstat;
-               stat_subheader_t stat;  
-       } subheader;
-} msg_t;
-
-typedef struct response {
-       int32_t ret;
-       uint32_t err;
-       struct stat st;
-       char buf[0];
-} response_t;
-
-#undef errno
-extern int errno;
-
-response_t* handle_open(msg_t * msg);
-response_t* handle_close(msg_t * msg);
-response_t* handle_read(msg_t * msg);
-response_t* handle_write(msg_t * msg);
-response_t* handle_lseek(msg_t * msg);
-response_t* handle_isatty(msg_t * msg);
-response_t* handle_unlink(msg_t * msg);
-response_t* handle_link(msg_t * msg);
-response_t* handle_stat(msg_t * msg);
-response_t* handle_fstat(msg_t * msg);
-
-int listen_for_connections();
-int setup_data_connection(int data_port);
-void process_connections(int fd);
-int read_from_socket(char* buf, int socket, int len, int peek);
-int read_header_from_socket(msg_t* msg, int socket);
-int read_buffer_from_socket(char* buf, int socket, int len);
-void send_error(int fd);
diff --git a/tools/syscall_server/.ros_slave_pty b/tools/syscall_server/.ros_slave_pty
new file mode 100644 (file)
index 0000000..5bc6e41
--- /dev/null
@@ -0,0 +1 @@
+/dev/pts/2
\ No newline at end of file
diff --git a/tools/syscall_server/Makefile b/tools/syscall_server/Makefile
new file mode 100644 (file)
index 0000000..d6ad21d
--- /dev/null
@@ -0,0 +1,12 @@
+
+all: syscall_server
+
+translate_state.o: translate_state.c syscall_server.h
+       gcc -c -I. -o translate_state.o translate_state.c 
+
+syscall_server: translate_state.o syscall_server.h syscall_server.c
+       gcc -I. -o syscall_server translate_state.o syscall_server.c 
+
+clean:
+       rm -rf *.o
+       rm -rf syscall_server
diff --git a/tools/syscall_server/newlib_stat.h b/tools/syscall_server/newlib_stat.h
new file mode 100644 (file)
index 0000000..672fe3d
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef NEWLIB_STRUCT_H
+#define NEWLIB_STRUCT_H
+
+#include <stdint.h>
+
+// For translating the stat structure
+typedef struct newlib_stat {
+       int16_t st_dev;
+       uint16_t st_ino;
+       uint32_t st_mode;
+       uint16_t st_nlink;
+       uint16_t st_uid;
+       uint16_t st_gid;
+       int16_t st_rdev;
+       int32_t st_size;
+       int32_t st_atim;
+       int32_t st_spare1;
+       int32_t st_mtim;
+       int32_t st_spare2;
+       int32_t st_ctim;
+       int32_t st_spare3;
+       int32_t st_blksize;
+       int32_t st_blocks;
+       int32_t st_spare4[2];
+} newlib_stat_t;
+
+// For translating the open flags
+#define NEWLIB_O_RDONLY    0x0000 
+#define NEWLIB_O_WRONLY    0x0001
+#define NEWLIB_O_RDWR      0x0002
+#define NEWLIB_O_APPEND    0x0008
+#define NEWLIB_O_CREAT     0x0200
+#define NEWLIB_O_TRUNC     0x0400
+#define NEWLIB_O_EXCL      0x0800
+
+// For translating the open modes
+#define NEWLIB_S_IRWXU     \
+        (NEWLIB_S_IRUSR | NEWLIB_S_IWUSR | NEWLIBS_IXUSR)
+#define     NEWLIB_S_IRUSR 0000400 /* read permission, owner */
+#define     NEWLIB_S_IWUSR 0000200 /* write permission, owner */
+#define     NEWLIB_S_IXUSR 0000100/* execute/search permission, owner */
+#define NEWLIB_S_IRWXG     \
+        (NEWLIB_S_IRGRP | NEWLIB_S_IWGRP | NEWLIB_S_IXGRP)
+#define     NEWLIB_S_IRGRP 0000040 /* read permission, group */
+#define     NEWLIB_S_IWGRP 0000020 /* write permission, grougroup */
+#define     NEWLIB_S_IXGRP 0000010/* execute/search permission, group */
+#define NEWLIB_S_IRWXO     \
+        (NEWLIB_S_IROTH | NEWLIB_S_IWOTH | NEWLIB_S_IXOTH)
+#define     NEWLIB_S_IROTH 0000004 /* read permission, other */
+#define     NEWLIB_S_IWOTH 0000002 /* write permission, other */
+#define     NEWLIB_S_IXOTH 0000001/* execute/search permission, other */
+
+// For translating lseek's whence
+# define    SEEK_SET    0
+# define    SEEK_CUR    1
+# define    SEEK_END    2
+
+#endif
diff --git a/tools/syscall_server/syscall_server.c b/tools/syscall_server/syscall_server.c
new file mode 100644 (file)
index 0000000..cc4f82a
--- /dev/null
@@ -0,0 +1,306 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <malloc.h>
+#include "syscall_server.h"
+
+#define debug(...) printf(__VA_ARGS__)  
+
+int main()
+{
+       run_server();
+       return 0;
+}
+
+// Poll for incoming messages and send responses. 
+void run_server() 
+{
+       // Struct for reading the syscall over the serial port
+       syscall_req_t syscall_req;
+       syscall_rsp_t syscall_rsp;
+
+       // File descriptor of our open serial port
+       int fd = posix_openpt(O_RDWR | O_NOCTTY);
+       grantpt (fd);
+    unlockpt (fd);
+       char* slave_dev = ptsname(fd);
+       printf("Master PTY fd: %d\n", fd);
+       printf("Slave  TTY device name: %s\n", slave_dev);
+       printf("\nStarting server.....\n");
+       fflush(stdout);
+       
+       //Output the newly allocated slave device into a file
+       int slave_fd = open(ROS_SLAVE_PTY, 
+                      O_RDWR | O_CREAT | O_TRUNC, 
+                      S_IRUSR | S_IWUSR);
+       write(slave_fd, slave_dev, strnlen(slave_dev));
+
+       // Continuously read in data from the serial port socket
+       while(1) {
+               syscall_req.payload_len = 0;
+               syscall_req.payload = NULL;
+               syscall_rsp.payload_len = 0;
+               syscall_rsp.payload = NULL;
+       
+               debug("\nWaiting for syscall...\n");
+               read_syscall_req(fd, &syscall_req);     
+               debug("Processing syscall: %d\n", syscall_req.header.id);
+               handle_syscall(&syscall_req, &syscall_rsp);
+               debug("Writing response: %d\n", syscall_req.header.id);
+               write_syscall_rsp(fd, &syscall_rsp);
+
+               if(syscall_req.payload != NULL)
+                       free(syscall_req.payload);
+               if(syscall_rsp.payload != NULL)
+                       free(syscall_rsp.payload);
+       }
+}
+
+void read_syscall_req(int fd, syscall_req_t* req) 
+{
+       read_syscall_req_header(fd, req);
+       debug("Read Header for :%d...\n", req->header.id);
+       set_syscall_req_payload_len(req);
+       read_syscall_req_payload(fd, req);
+       debug("Read Payload...\n");
+}
+
+void set_syscall_req_payload_len(syscall_req_t* req)
+{
+       switch(req->header.id) {
+               case OPEN_ID:
+                       req->payload_len = req->header.subheader.open.len;
+                       break;
+               case WRITE_ID:
+                       req->payload_len = req->header.subheader.write.len;
+                       break;
+               case LINK_ID:
+                       req->payload_len = req->header.subheader.link.old_len
+                                          + req->header.subheader.link.new_len;
+                       break;
+               case UNLINK_ID:
+                       req->payload_len = req->header.subheader.unlink.len;
+                       break;
+               case STAT_ID:
+                       req->payload_len = req->header.subheader.stat.len;
+                       break;
+       }
+}
+
+void read_syscall_req_header(int fd, syscall_req_t* req) 
+{
+       // Try to read the syscall id from the socket.
+       // If no data available, spin until there is
+       int bytes_read = 0;
+       bytes_read = read_from_serial(fd, &req->header, sizeof(req->header.id), 0);
+
+       // If no data, or the ID we got is bad, terminate process.
+       uint32_t id = req->header.id;
+       if ((bytes_read < 0) || (id < 0) || (id > NUM_SYSCALLS)) {
+               printf("Bytes Read: %d\n", bytes_read);
+               perror("Problems reading the id from the serial port...");
+       }
+
+       // Otherwise, start grabbing the rest of the data
+       bytes_read = read_from_serial(fd, &req->header.subheader, 
+                                  sizeof(req->header.subheader) , 0);
+
+       if(bytes_read < 0)
+               error(fd, "Problems reading header from the serial port...");
+}
+
+void read_syscall_req_payload(int fd, syscall_req_t* req) {
+       if (req->payload_len == 0)
+               return;
+               
+       req->payload = malloc(req->payload_len);
+       if (req->payload == NULL) 
+               error(fd, "No free memory!");
+
+       int bytes_read = read_from_serial(fd, req->payload, req->payload_len, 0);
+       if (bytes_read < 0)
+               error(fd, "Problems reading payload from serial port");
+}
+
+// Read len bytes from the given socket to the buffer.
+// If peek is 0, will wait indefinitely until that much data is read.
+// If peek is 1, if no data is available, will return immediately.
+int read_from_serial(int fd, void* buf, int len, int peek) 
+{
+       int total_read = 0;
+       int just_read = read(fd, buf, len);
+
+       if (just_read < 0) return just_read;
+       if (just_read == 0 && peek) return just_read;
+
+       total_read += just_read;
+
+       while (total_read != len) {
+               just_read = read(fd, buf + total_read, len - total_read);
+               if (just_read < 0) return just_read;
+               total_read += just_read;
+       }
+       return total_read;
+}
+
+// Send CONNECTION_TERMINATED over the FD (if possible)
+void error(int fd, const char* s)
+{
+       printf("Error: Spawned Process, FD: %i\n",fd);
+       perror(s);
+    printf("Sending CONNECTION_TERMINATED.... \n");
+       close(fd);
+       exit(-1);
+}
+
+void handle_syscall(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       switch (req->header.id) {
+               case OPEN_ID:
+                       handle_open(req, rsp);
+                       break;
+               case CLOSE_ID:
+                       handle_close(req, rsp);
+                       break;
+               case READ_ID:
+                       handle_read(req, rsp);
+                       break;
+               case WRITE_ID:
+                       handle_write(req, rsp);
+                       break;
+               case LINK_ID:
+                       handle_link(req, rsp);
+                       break;
+               case UNLINK_ID:
+                       handle_unlink(req, rsp);
+                       break;
+               case LSEEK_ID:
+                       handle_lseek(req, rsp);
+                       break;
+               case FSTAT_ID:
+                       handle_fstat(req, rsp);
+                       break;
+               case ISATTY_ID:
+                       handle_isatty(req, rsp);
+                       break;
+               case STAT_ID:
+                       handle_stat(req, rsp);
+                       break;
+               default:
+                       error(-1, "Illegal syscall, should never be here...");
+       }
+       
+       rsp->header.return_errno = errno;
+}
+
+void write_syscall_rsp(int fd, syscall_rsp_t* rsp) 
+{
+       write_syscall_rsp_header(fd, rsp);
+       write_syscall_rsp_payload(fd, rsp);
+}
+
+void write_syscall_rsp_header(int fd, syscall_rsp_t* rsp) 
+{
+       int written = write(fd, &rsp->header, sizeof(syscall_rsp_header_t));
+       if (written < 0)
+               error(fd, "Problems writing the syscall response header...");   
+}
+
+void write_syscall_rsp_payload(int fd, syscall_rsp_t* rsp) 
+{
+       if(rsp->payload_len == 0)
+               return;
+
+       int written = write(fd, rsp->payload, rsp->payload_len);
+       if (written < 0)
+               error(fd, "Problems writing the syscall response payload...");  
+       if (written < rsp->payload_len)
+               error(fd, "Problems writing all bytes in the response payload...");     
+}
+
+void handle_open(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       open_subheader_t* o = &req->header.subheader.open;      
+       debug("Flags: %d\n", o->flags);
+       debug("Newlib Flags: %d\n", O_RDWR | O_CREAT | O_TRUNC);
+       debug("Mode: %d\n", o->mode);
+       debug("Newlib Mode: %d\n", 
+           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+       rsp->header.return_val = open(req->payload, o->flags, o->mode);
+       debug("Return Value: %d\n", rsp->header.return_val);
+       debug("Payload: %s\n", (char*)req->payload);
+}
+
+void handle_close(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       close_subheader_t* c = &req->header.subheader.close;    
+       rsp->header.return_val = close(c->fd);
+}
+
+void handle_read(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       read_subheader_t* r = &req->header.subheader.read;      
+       rsp->payload = malloc(r->len);
+       debug("File descriptor: %d\n", r->fd);
+       debug("Length to read: %d\n", r->len);
+       rsp->header.return_val = read(r->fd, rsp->payload, r->len);
+       if(rsp->header.return_val >= 0)
+               rsp->payload_len = rsp->header.return_val;
+}
+
+void handle_write(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       write_subheader_t* w = &req->header.subheader.write;    
+       rsp->header.return_val = write(w->fd, req->payload, w->len);
+}
+
+void handle_link(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       link_subheader_t* l = &req->header.subheader.link;      
+       rsp->header.return_val = link(req->payload, 
+                                  req->payload + l->old_len);
+}
+
+void handle_unlink(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       rsp->header.return_val = unlink(req->payload); 
+}
+
+void handle_lseek(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       lseek_subheader_t* l = &req->header.subheader.lseek;    
+       rsp->header.return_val = lseek(l->fd, l->ptr, l->dir);
+}
+
+void handle_fstat(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       struct stat native_struct;
+       fstat_subheader_t* f = &req->header.subheader.fstat;    
+       rsp->payload = malloc(sizeof(newlib_stat_t));
+       rsp->header.return_val = fstat(f->fd, &native_struct); 
+       if(rsp->header.return_val >= 0)
+               rsp->payload_len = sizeof(newlib_stat_t);
+       
+       translate_stat(&native_struct, (newlib_stat_t*)(rsp->payload));
+}
+
+void handle_isatty(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       isatty_subheader_t* i = &req->header.subheader.isatty;  
+       rsp->header.return_val = isatty(i->fd); 
+}
+
+void handle_stat(syscall_req_t* req, syscall_rsp_t* rsp)
+{
+       struct stat native_struct;
+       rsp->payload = malloc(sizeof(newlib_stat_t));
+       rsp->header.return_val = stat(req->payload, &native_struct); 
+       if(rsp->header.return_val >= 0)
+               rsp->payload_len = sizeof(newlib_stat_t);
+
+       translate_stat(&native_struct, (newlib_stat_t*)(rsp->payload));
+}
+
diff --git a/tools/syscall_server/syscall_server.h b/tools/syscall_server/syscall_server.h
new file mode 100644 (file)
index 0000000..2427436
--- /dev/null
@@ -0,0 +1,144 @@
+#ifndef SERIAL_SERVER_H
+#define SERIAL_SERVER_H
+
+#include <stdint.h>
+#include <newlib_stat.h>
+
+#define ROS_SLAVE_PTY ".ros_slave_pty"
+
+#define OPEN_ID                        0
+#define CLOSE_ID               1
+#define READ_ID                        2
+#define WRITE_ID               3
+#define LINK_ID                        4
+#define UNLINK_ID              5
+#define LSEEK_ID               6
+#define FSTAT_ID               7
+#define ISATTY_ID              8
+#define STAT_ID                        9
+#define NUM_SYSCALLS   10
+
+typedef uint32_t syscall_id_t;
+
+typedef struct open_subheader {
+       uint32_t flags;
+       uint32_t mode;
+       uint32_t len;
+} open_subheader_t;
+
+typedef struct close_subheader {
+       uint32_t fd;
+       uint32_t FILL1;
+       uint32_t FILL2;
+} close_subheader_t;
+
+typedef struct read_subheader {
+       uint32_t fd;
+       uint32_t len;
+       uint32_t FILL1;
+} read_subheader_t;
+
+typedef struct write_subheader {
+       uint32_t fd;
+       uint32_t len;
+       uint32_t FILL1;
+} write_subheader_t;
+
+typedef struct lseek_subheader {
+       uint32_t fd;
+       uint32_t ptr;
+       uint32_t dir;
+} lseek_subheader_t;
+
+typedef struct isatty_subheader {
+       uint32_t fd;
+       uint32_t FILL1;
+       uint32_t FILL2;
+} isatty_subheader_t;
+
+typedef struct link_subheader {
+       uint32_t old_len;
+       uint32_t new_len;
+       uint32_t FILL1;
+} link_subheader_t;
+
+typedef struct unlink_subheader {
+       uint32_t len;
+       uint32_t FILL1;
+       uint32_t FILL2;
+} unlink_subheader_t;
+
+typedef struct fstat_subheader {
+       uint32_t fd;
+       uint32_t FILL1;
+       uint32_t FILL2;
+} fstat_subheader_t;
+
+typedef struct stat_subheader {
+       uint32_t len;
+       uint32_t FILL1;
+       uint32_t FILL2;
+} stat_subheader_t;
+
+typedef struct syscall_req_header {
+       syscall_id_t id;
+       union {
+               open_subheader_t open;
+               close_subheader_t close;
+               read_subheader_t read;
+               write_subheader_t write;
+               lseek_subheader_t lseek;
+               isatty_subheader_t isatty;
+               link_subheader_t link;
+               unlink_subheader_t unlink;
+               fstat_subheader_t fstat;
+               stat_subheader_t stat;  
+       } subheader;
+} syscall_req_header_t;
+
+typedef struct syscall_req {
+       syscall_req_header_t header;
+       uint32_t payload_len;
+       void* payload;
+} syscall_req_t;
+
+typedef struct syscall_rsp_header {
+       int32_t return_val;
+       uint32_t return_errno;
+} syscall_rsp_header_t;
+
+typedef struct syscall_rsp {
+       syscall_rsp_header_t header;
+       uint32_t payload_len;
+       void* payload;
+} syscall_rsp_t;
+
+void run_server();
+void translate_stat(struct stat* native, struct newlib_stat* newlib);
+void translate_flags(int native, int newlib);
+void translate_mode(int native, int newlib);
+void translate_dir(int native, int newlib);
+void translate_errno(int native, int newlib);
+void set_syscall_req_payload_len(syscall_req_t* req);
+void read_syscall_req(int fd, syscall_req_t* req);
+void read_syscall_req_header(int fd, syscall_req_t* req);
+void read_syscall_req_payload(int fd, syscall_req_t* req);
+void write_syscall_rsp(int fd, syscall_rsp_t* rsp);
+void write_syscall_rsp_header(int fd, syscall_rsp_t* rsp);
+void write_syscall_rsp_payload(int fd, syscall_rsp_t* rsp);
+int read_from_serial(int fd, void* buf, int len, int peek); 
+void error(int fd, const char* s);
+
+void handle_syscall(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_open(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_close(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_read(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_write(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_link(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_unlink(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_lseek(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_fstat(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_isatty(syscall_req_t* req, syscall_rsp_t* rsp);
+void handle_stat(syscall_req_t* req, syscall_rsp_t* rsp);
+
+#endif //SERIAL_SERVER_H
diff --git a/tools/syscall_server/test/input b/tools/syscall_server/test/input
new file mode 100644 (file)
index 0000000..fb1bcb5
--- /dev/null
@@ -0,0 +1 @@
+Shit for brains
diff --git a/tools/syscall_server/translate_state.c b/tools/syscall_server/translate_state.c
new file mode 100644 (file)
index 0000000..7f2129a
--- /dev/null
@@ -0,0 +1,26 @@
+#include <sys/stat.h>
+#include <stdio.h>
+#include <newlib_stat.h>
+#include "syscall_server.h"
+
+void translate_stat(struct stat* native, struct newlib_stat* newlib) {
+       newlib->st_dev = native->st_dev;
+       newlib->st_ino = native->st_ino;
+       newlib->st_mode = native->st_mode;
+       newlib->st_nlink = native->st_nlink;
+       newlib->st_uid = native->st_uid;
+       newlib->st_gid = native->st_gid;
+       newlib->st_rdev = native->st_rdev;
+       newlib->st_size = native->st_size;
+       newlib->st_atim = native->st_atim.tv_nsec;
+       newlib->st_mtim = native->st_mtim.tv_nsec;
+       newlib->st_ctim = native->st_ctim.tv_nsec;
+       newlib->st_blksize = native->st_blksize;
+       newlib->st_blocks = native->st_blocks;
+}
+void translate_flags(int native, int newlib) {
+}
+void translate_mode(int native, int newlib) {
+}
+void translate_dir(int native, int newlib) {
+}
index a99a8c9..269e5db 100644 (file)
@@ -9,7 +9,7 @@
 
 
 
-#define debug_in_out(...) // debug(__VA_ARGS__)  
+#define debug_in_out(...) //debug(__VA_ARGS__)  
 #define debug_write_check(fmt, ...)  //debug(fmt, __VA_ARGS__)
 
 typedef uint32_t syscall_id_t;
@@ -128,7 +128,6 @@ typedef struct backend_msg {
 typedef struct response {
        int32_t ret;
        uint32_t err;
-       struct stat st;
        char (CT(ret) buf)[0];
 } response_t;
 
index 34a0fbf..06a71a9 100644 (file)
-/*-
- * Copyright (c) 1982, 1986, 1989, 1993
- *      The Regents of the University of California.  All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *      @(#)stat.h      8.12 (Berkeley) 6/16/95
- * $FreeBSD: src/sys/sys/stat.h,v 1.46 2009/03/14 19:11:08 das Exp $
- */
+#ifndef        _SYS_STAT_H
+#define        _SYS_STAT_H
 
-#ifndef _SYS_STAT_H_
-#define _SYS_STAT_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #include <_ansi.h>
 #include <time.h>
 #include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/_types.h>
-
-#define        S_IFMT          _IFMT
-#define _S_IFMT                _IFMT
-
-/*
- * Standard type definitions.
- */
-typedef __uint32_t      __blksize_t;    /* file block size */
-typedef __int64_t       __blkcnt_t;     /* file block count */
-typedef __int32_t       __clockid_t;    /* clock_gettime()... */
-typedef __uint32_t      __fflags_t;     /* file flags */
-typedef __uint64_t      __fsblkcnt_t;
-typedef __uint64_t      __fsfilcnt_t;
-//typedef __uint32_t      __gid_t;
-typedef __int64_t       __id_t;         /* can hold a gid_t, pid_t, or uid_t */
-typedef __uint32_t      __ino_t;        /* inode number */
-typedef long            __key_t;        /* IPC key (for Sys V IPC) */
-typedef __int32_t       __lwpid_t;      /* Thread ID (a.k.a. LWP) */
-typedef __uint16_t      __mode_t;       /* permissions */
-typedef int             __accmode_t;    /* access permissions */
-typedef int             __nl_item;
-typedef __uint16_t      __nlink_t;      /* link count */
-//typedef __int64_t       __off_t;        /* file offset */
-//typedef __int32_t       __pid_t;        /* process [group] */
-typedef __int64_t       __rlim_t;       /* resource limit - intentionally */
-                                        /* signed, because of legacy code */
-                                        /* that uses -1 for RLIM_INFINITY */
-typedef __uint8_t       __sa_family_t;
-typedef __uint32_t      __socklen_t;
-typedef long            __suseconds_t;  /* microseconds (signed) */
-typedef struct __timer  *__timer_t;     /* timer_gettime()... */
-typedef struct __mq     *__mqd_t;       /* mq_open()... */
-//typedef __uint32_t      __uid_t;
-typedef unsigned int    __useconds_t;   /* microseconds (unsigned) */
-typedef int             __cpuwhich_t;   /* which parameter for cpuset. */
-typedef int             __cpulevel_t;   /* level parameter for cpuset. */
-typedef int             __cpusetid_t;   /* cpuset identifier. */
-
-/*
- * Unusual type definitions.
- */
-/*
- * rune_t is declared to be an ``int'' instead of the more natural
- * ``unsigned long'' or ``long''.  Two things are happening here.  It is not
- * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,
- * it looks like 10646 will be a 31 bit standard.  This means that if your
- * ints cannot hold 32 bits, you will be in trouble.  The reason an int was
- * chosen over a long is that the is*() and to*() routines take ints (says
- * ANSI C), but they use __ct_rune_t instead of int.
- *
- * NOTE: rune_t is not covered by ANSI nor other standards, and should not
- * be instantiated outside of lib/libc/locale.  Use wchar_t.  wchar_t and
- * rune_t must be the same type.  Also, wint_t must be no narrower than
- * wchar_t, and should be able to hold all members of the largest
- * character set plus one extra value (WEOF), and must be at least 16 bits.
- */
-typedef int             __ct_rune_t;    /* arg type for ctype funcs */
-typedef __ct_rune_t     __rune_t;       /* rune_t (see above) */
-typedef __ct_rune_t     __wchar_t;      /* wchar_t (see above) */
-typedef __ct_rune_t     __wint_t;       /* wint_t (see above) */
-
-//typedef __uint32_t      __dev_t;        /* device number */
-
-typedef __uint32_t      __fixpt_t;      /* fixed point number */
-
-/*
- * mbstate_t is an opaque object to keep conversion state during multibyte
- * stream conversions.
- */
-typedef union {
-        char            __mbstate8[128];
-        __int64_t       _mbstateL;      /* for alignment */
-} __mbstate_t;
-
-#ifndef _BLKSIZE_T_DECLARED
-typedef __blksize_t     blksize_t;
-#define _BLKSIZE_T_DECLARED
-#endif
-
-#ifndef _BLKCNT_T_DECLARED
-typedef __blkcnt_t      blkcnt_t;
-#define _BLKCNT_T_DECLARED
-#endif
-
-#ifndef _DEV_T_DECLARED
-//typedef __dev_t         dev_t;
-#define _DEV_T_DECLARED
-#endif
 
-#ifndef _FFLAGS_T_DECLARED
-typedef __fflags_t      fflags_t;
-#define _FFLAGS_T_DECLARED
-#endif
+/* dj's stat defines _STAT_H_ */
+#ifndef _STAT_H_
 
-#ifndef _GID_T_DECLARED
-//typedef __gid_t         gid_t;
-#define _GID_T_DECLARED
-#endif
+/* It is intended that the layout of this structure not change when the
+   sizes of any of the basic types change (short, int, long) [via a compile
+   time option].  */
 
-#ifndef _INO_T_DECLARED
-//typedef __ino_t         ino_t;
-#define _INO_T_DECLARED
+#ifdef __CYGWIN__
+#include <cygwin/stat.h>
+#ifdef _COMPILING_NEWLIB
+#define stat64 __stat64
 #endif
-
-#ifndef _MODE_T_DECLARED
-//typedef __mode_t        mode_t;
-#define _MODE_T_DECLARED
-#endif
-
-#ifndef _NLINK_T_DECLARED
-//typedef __nlink_t       nlink_t;
-#define _NLINK_T_DECLARED
-#endif
-
-#ifndef _OFF_T_DECLARED
-//typedef __off_t         off_t;
-#define _OFF_T_DECLARED
-#endif
-
-#ifndef _TIME_T_DECLARED
-//typedef __time_t        time_t;
-typedef time_t                 __time_t;
-#define _TIME_T_DECLARED
-#endif
-
-#ifndef _UID_T_DECLARED
-//typedef __uid_t         uid_t;
-#define _UID_T_DECLARED
-#endif
-
-#if !defined(_KERNEL) && __BSD_VISIBLE
-/*
- * XXX we need this for struct timespec.  We get miscellaneous namespace
- * pollution with it.
- */
-#include <sys/time.h>
-#endif
-
-#if !__BSD_VISIBLE
-struct __timespec {
-       __time_t tv_sec;        /* seconds */
-       long    tv_nsec;        /* and nanoseconds */
-};
-#endif
-
-#if __BSD_VISIBLE
-struct ostat {
-        __uint16_t st_dev;              /* inode's device */
-        ino_t     st_ino;               /* inode's number */
-        mode_t    st_mode;              /* inode protection mode */
-        nlink_t   st_nlink;             /* number of hard links */
-        __uint16_t st_uid;              /* user ID of the file's owner */
-        __uint16_t st_gid;              /* group ID of the file's group */
-        __uint16_t st_rdev;             /* device type */
-        __int32_t st_size;              /* file size, in bytes */
-        struct  timespec st_atimespec;  /* time of last access */
-        struct  timespec st_mtimespec;  /* time of last data modification */
-        struct  timespec st_ctimespec;  /* time of last file status change */
-        __int32_t st_blksize;           /* optimal blocksize for I/O */
-        __int32_t st_blocks;            /* blocks allocated for file */
-        fflags_t  st_flags;             /* user defined flags for file */
-        __uint32_t st_gen;              /* file generation number */
-};
-#endif /* __BSD_VISIBLE */
-
-struct stat {
- __int32_t st_dev;
- __int32_t st_ino;
- __int16_t st_mode;
- __int16_t st_nlink;
- __int32_t st_uid;
- __int32_t st_gid;
- __int32_t st_rdev;
-
- struct timespec st_atimespec;
- struct timespec st_mtimespec;
- struct timespec st_ctimespec;
-
- __int64_t st_size;
- blkcnt_t st_blocks;
- blksize_t st_blksize;
- __uint32_t st_flags;
- __uint32_t st_gen;
- __int32_t st_lspare;
- __int64_t st_qspare[2];
-};
-
-#if 0
-struct stat {
-        __dev_t   st_dev;               /* inode's device */
-        ino_t     st_ino;               /* inode's number */
-        mode_t    st_mode;              /* inode protection mode */
-        nlink_t   st_nlink;             /* number of hard links */
-        uid_t     st_uid;               /* user ID of the file's owner */
-        gid_t     st_gid;               /* group ID of the file's group */
-        __dev_t   st_rdev;              /* device type */
-#if __BSD_VISIBLE
-        struct  timespec st_atimespec;  /* time of last access */
-        struct  timespec st_mtimespec;  /* time of last data modification */
-        struct  timespec st_ctimespec;  /* time of last file status change */
 #else
-        time_t    st_atime;             /* time of last access */
-        long      __st_atimensec;       /* nsec of last access */
-        time_t    st_mtime;             /* time of last data modification */
-        long      __st_mtimensec;       /* nsec of last data modification */
-        time_t    st_ctime;             /* time of last file status change */
-        long      __st_ctimensec;       /* nsec of last file status change */
-#endif
-        off_t     st_size;              /* file size, in bytes */
-        blkcnt_t st_blocks;             /* blocks allocated for file */
-        blksize_t st_blksize;           /* optimal blocksize for I/O */
-        fflags_t  st_flags;             /* user defined flags for file */
-        __uint32_t st_gen;              /* file generation number */
-        __int32_t st_lspare;
-#if __BSD_VISIBLE
-        struct timespec st_birthtimespec; /* time of file creation */
-        /*
-         * Explicitly pad st_birthtimespec to 16 bytes so that the size of
-         * struct stat is backwards compatible.  We use bitfields instead
-         * of an array of chars so that this doesn't require a C99 compiler
-         * to compile if the size of the padding is 0.  We use 2 bitfields
-         * to cover up to 64 bits on 32-bit machines.  We assume that
-         * CHAR_BIT is 8...
-         */
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
+struct stat 
+{
+  dev_t                st_dev;
+  ino_t                st_ino;
+  mode_t       st_mode;
+  nlink_t      st_nlink;
+  uid_t                st_uid;
+  gid_t                st_gid;
+  dev_t                st_rdev;
+  off_t                st_size;
+  /* SysV/sco doesn't have the rest... But Solaris, eabi does.  */
+#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
+  time_t       st_atime;
+  time_t       st_mtime;
+  time_t       st_ctime;
 #else
-        time_t    st_birthtime;         /* time of file creation */
-        long      st_birthtimensec;     /* nsec of file creation */
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
-#endif
-};
+  time_t       st_atime;
+  long         st_spare1;
+  time_t       st_mtime;
+  long         st_spare2;
+  time_t       st_ctime;
+  long         st_spare3;
+  long         st_blksize;
+  long         st_blocks;
+  long st_spare4[2];
 #endif
-
-
-#if __BSD_VISIBLE
-struct nstat {
-        __dev_t   st_dev;               /* inode's device */
-        ino_t     st_ino;               /* inode's number */
-        __uint32_t st_mode;             /* inode protection mode */
-        __uint32_t st_nlink;            /* number of hard links */
-        uid_t     st_uid;               /* user ID of the file's owner */
-        gid_t     st_gid;               /* group ID of the file's group */
-        __dev_t   st_rdev;              /* device type */
-        struct  timespec st_atimespec;  /* time of last access */
-        struct  timespec st_mtimespec;  /* time of last data modification */
-        struct  timespec st_ctimespec;  /* time of last file status change */
-        off_t     st_size;              /* file size, in bytes */
-        blkcnt_t st_blocks;             /* blocks allocated for file */
-        blksize_t st_blksize;           /* optimal blocksize for I/O */
-        fflags_t  st_flags;             /* user defined flags for file */
-        __uint32_t st_gen;              /* file generation number */
-        struct timespec st_birthtimespec; /* time of file creation */
-        /*
-         * See above about the following padding.
-         */
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
-        unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
 };
 #endif
 
-#if __BSD_VISIBLE
-#define st_atime st_atimespec.tv_sec
-#define st_mtime st_mtimespec.tv_sec
-#define st_ctime st_ctimespec.tv_sec
-#define st_birthtime st_birthtimespec.tv_sec
-#endif
-
-#define     _IFMT   0170000 /* type of file */
-#define     _IFDIR  0040000 /* directory */
-#define     _IFCHR  0020000 /* character special */
-#define     _IFBLK  0060000 /* block special */
-#define     _IFREG  0100000 /* regular */
-#define     _IFLNK  0120000 /* symbolic link */
-#define     _IFSOCK 0140000 /* socket */
-#define     _IFIFO  0010000 /* fifo */
-
-#define S_IFMT      _IFMT
-#define S_IFDIR     _IFDIR
-#define S_IFCHR     _IFCHR
-#define S_IFBLK     _IFBLK
-#define S_IFREG     _IFREG
-#define S_IFLNK     _IFLNK
-#define S_IFSOCK    _IFSOCK
-#define S_IFIFO     _IFIFO
-
-#define S_ISUID 0004000                 /* set user id on execution */
-#define S_ISGID 0002000                 /* set group id on execution */
-#if __BSD_VISIBLE
-#define S_ISTXT 0001000                 /* sticky bit */
-#endif
-
-#define S_IRWXU 0000700                 /* RWX mask for owner */
-#define S_IRUSR 0000400                 /* R for owner */
-#define S_IWUSR 0000200                 /* W for owner */
-#define S_IXUSR 0000100                 /* X for owner */
-
-#if __BSD_VISIBLE
-#define S_IREAD         S_IRUSR
-#define S_IWRITE        S_IWUSR
-#define S_IEXEC         S_IXUSR
-#endif
-
-#define S_IRWXG 0000070                 /* RWX mask for group */
-#define S_IRGRP 0000040                 /* R for group */
-#define S_IWGRP 0000020                 /* W for group */
-#define S_IXGRP 0000010                 /* X for group */
-
-#define S_IRWXO 0000007                 /* RWX mask for other */
-#define S_IROTH 0000004                 /* R for other */
-#define S_IWOTH 0000002                 /* W for other */
-#define S_IXOTH 0000001                 /* X for other */
-
-#if __XSI_VISIBLE
-#define S_IFMT   0170000                /* type of file mask */
-#define S_IFIFO  0010000                /* named pipe (fifo) */
-#define S_IFCHR  0020000                /* character special */
-#define S_IFDIR  0040000                /* directory */
-#define S_IFBLK  0060000                /* block special */
-#define S_IFREG  0100000                /* regular */
-#define S_IFLNK  0120000                /* symbolic link */
-#define S_IFSOCK 0140000                /* socket */
-#define S_ISVTX  0001000                /* save swapped text even after use */
-#endif
-#if __BSD_VISIBLE
-#define S_IFWHT  0160000                /* whiteout */
-#endif
-
-#define S_ISDIR(m)      (((m) & 0170000) == 0040000)    /* directory */
-#define S_ISCHR(m)      (((m) & 0170000) == 0020000)    /* char special */
-#define S_ISBLK(m)      (((m) & 0170000) == 0060000)    /* block special */
-#define S_ISREG(m)      (((m) & 0170000) == 0100000)    /* regular file */
-#define S_ISFIFO(m)     (((m) & 0170000) == 0010000)    /* fifo or socket */
-#if __POSIX_VISIBLE >= 200112
-#define S_ISLNK(m)      (((m) & 0170000) == 0120000)    /* symbolic link */
-#define S_ISSOCK(m)     (((m) & 0170000) == 0140000)    /* socket */
-#endif
-#if __BSD_VISIBLE
-#define S_ISWHT(m)      (((m) & 0170000) == 0160000)    /* whiteout */
-#endif
-
-#if __BSD_VISIBLE
-#define ACCESSPERMS     (S_IRWXU|S_IRWXG|S_IRWXO)       /* 0777 */
-                                                        /* 7777 */
-#define ALLPERMS        (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
-                                                        /* 0666 */
-#define DEFFILEMODE     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
-
-#define S_BLKSIZE       512             /* block size used in the stat struct */
-
-/*
- * Definitions of flags stored in file flags word.
- *
- * Super-user and owner changeable flags.
- */
-#define UF_SETTABLE     0x0000ffff      /* mask of owner changeable flags */
-#define UF_NODUMP       0x00000001      /* do not dump file */
-#define UF_IMMUTABLE    0x00000002      /* file may not be changed */
-#define UF_APPEND       0x00000004      /* writes to file may only append */
-#define UF_OPAQUE       0x00000008      /* directory is opaque wrt. union */
-#define UF_NOUNLINK     0x00000010      /* file may not be removed or renamed */
-/*
- * Super-user changeable flags.
- */
-#define SF_SETTABLE     0xffff0000      /* mask of superuser changeable flags */
-#define SF_ARCHIVED     0x00010000      /* file is archived */
-#define SF_IMMUTABLE    0x00020000      /* file may not be changed */
-#define SF_APPEND       0x00040000      /* writes to file may only append */
-#define SF_NOUNLINK     0x00100000      /* file may not be removed or renamed */
-#define SF_SNAPSHOT     0x00200000      /* snapshot inode */
+#define        _IFMT           0170000 /* type of file */
+#define                _IFDIR  0040000 /* directory */
+#define                _IFCHR  0020000 /* character special */
+#define                _IFBLK  0060000 /* block special */
+#define                _IFREG  0100000 /* regular */
+#define                _IFLNK  0120000 /* symbolic link */
+#define                _IFSOCK 0140000 /* socket */
+#define                _IFIFO  0010000 /* fifo */
 
-#ifdef _KERNEL
-/*
- * Shorthand abbreviations of above.
- */
-#define OPAQUE          (UF_OPAQUE)
-#define APPEND          (UF_APPEND | SF_APPEND)
-#define IMMUTABLE       (UF_IMMUTABLE | SF_IMMUTABLE)
-#define NOUNLINK        (UF_NOUNLINK | SF_NOUNLINK)
-#endif
+#define        S_BLKSIZE  1024 /* size of a block */
 
-#endif /* __BSD_VISIBLE */
-
-#ifndef _KERNEL
-__BEGIN_DECLS
-#if __BSD_VISIBLE
-int     chflags(const char *, unsigned long);
-#endif
-int     chmod(const char *, mode_t);
-#if __BSD_VISIBLE
-int     fchflags(int, unsigned long);
-#endif
-#if __POSIX_VISIBLE >= 200112
-int     fchmod(int, mode_t);
-#endif
-#if __POSIX_VISIBLE >= 200809
-int     fchmodat(int, const char *, mode_t, int);
-#endif
-int     fstat(int, struct stat *);
-#if __BSD_VISIBLE
-int     lchflags(const char *, int);
-int     lchmod(const char *, mode_t);
-#endif
-#if __POSIX_VISIBLE >= 200112
-int     lstat(const char * __restrict, struct stat * __restrict);
-#endif
-int     mkdir(const char *, mode_t);
-int     mkfifo(const char *, mode_t);
-#if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE
-int     mknod(const char *, mode_t, dev_t);
-#define _MKNOD_DECLARED
-#endif
-int     stat(const char * __restrict, struct stat * __restrict);
-mode_t  umask(mode_t);
-#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
-int     fstatat(int, const char *, struct stat *, int);
-int     mkdirat(int, const char *, mode_t);
-int     mkfifoat(int, const char *, mode_t);
-#endif
-#if __BSD_VISIBLE || __XSI_VISIBLE >= 700
-int     mknodat(int, const char *, mode_t, dev_t);
-#endif
-__END_DECLS
-#endif /* !_KERNEL */
-
-#endif /* !_SYS_STAT_H_ */
+#define        S_ISUID         0004000 /* set user id on execution */
+#define        S_ISGID         0002000 /* set group id on execution */
+#ifndef        _POSIX_SOURCE
+#define        S_ISVTX         0001000 /* save swapped text even after use */
+#define        S_IREAD         0000400 /* read permission, owner */
+#define        S_IWRITE        0000200 /* write permission, owner */
+#define        S_IEXEC         0000100 /* execute/search permission, owner */
+#define        S_ENFMT         0002000 /* enforcement-mode locking */
 
+#define        S_IFMT          _IFMT
+#define        S_IFDIR         _IFDIR
+#define        S_IFCHR         _IFCHR
+#define        S_IFBLK         _IFBLK
+#define        S_IFREG         _IFREG
+#define        S_IFLNK         _IFLNK
+#define        S_IFSOCK        _IFSOCK
+#define        S_IFIFO         _IFIFO
+#endif /* !_POSIX_SOURCE */
+
+#ifdef _WIN32
+/* The Windows header files define _S_ forms of these, so we do too
+   for easier portability.  */
+#define _S_IFMT                _IFMT
+#define _S_IFDIR       _IFDIR
+#define _S_IFCHR       _IFCHR
+#define _S_IFIFO       _IFIFO
+#define _S_IFREG       _IFREG
+#define _S_IREAD       0000400
+#define _S_IWRITE      0000200
+#define _S_IEXEC       0000100
+#endif
+
+#define        S_IRWXU         (S_IRUSR | S_IWUSR | S_IXUSR)
+#define                S_IRUSR 0000400 /* read permission, owner */
+#define                S_IWUSR 0000200 /* write permission, owner */
+#define                S_IXUSR 0000100/* execute/search permission, owner */
+#define        S_IRWXG         (S_IRGRP | S_IWGRP | S_IXGRP)
+#define                S_IRGRP 0000040 /* read permission, group */
+#define                S_IWGRP 0000020 /* write permission, grougroup */
+#define                S_IXGRP 0000010/* execute/search permission, group */
+#define        S_IRWXO         (S_IROTH | S_IWOTH | S_IXOTH)
+#define                S_IROTH 0000004 /* read permission, other */
+#define                S_IWOTH 0000002 /* write permission, other */
+#define                S_IXOTH 0000001/* execute/search permission, other */
+
+#define        S_ISBLK(m)      (((m)&_IFMT) == _IFBLK)
+#define        S_ISCHR(m)      (((m)&_IFMT) == _IFCHR)
+#define        S_ISDIR(m)      (((m)&_IFMT) == _IFDIR)
+#define        S_ISFIFO(m)     (((m)&_IFMT) == _IFIFO)
+#define        S_ISREG(m)      (((m)&_IFMT) == _IFREG)
+#define        S_ISLNK(m)      (((m)&_IFMT) == _IFLNK)
+#define        S_ISSOCK(m)     (((m)&_IFMT) == _IFSOCK)
+
+#if defined(__CYGWIN__)
+/* Special tv_nsec values for futimens(2) and utimensat(2). */
+#define UTIME_NOW      -2L
+#define UTIME_OMIT     -1L
+#endif
+
+int    _EXFUN(chmod,( const char *__path, mode_t __mode ));
+int     _EXFUN(fchmod,(int __fd, mode_t __mode));
+int    _EXFUN(fstat,( int __fd, struct stat *__sbuf ));
+int    _EXFUN(mkdir,( const char *_path, mode_t __mode ));
+int    _EXFUN(mkfifo,( const char *__path, mode_t __mode ));
+int    _EXFUN(stat,( const char *__path, struct stat *__sbuf ));
+mode_t _EXFUN(umask,( mode_t __mask ));
+
+#if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
+int    _EXFUN(lstat,( const char *__path, struct stat *__buf ));
+int    _EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev ));
+#endif
+
+#if defined (__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
+int    _EXFUN(fchmodat, (int, const char *, mode_t, int));
+int    _EXFUN(fstatat, (int, const char *, struct stat *, int));
+int    _EXFUN(mkdirat, (int, const char *, mode_t));
+int    _EXFUN(mkfifoat, (int, const char *, mode_t));
+int    _EXFUN(mknodat, (int, const char *, mode_t, dev_t));
+int    _EXFUN(utimensat, (int, const char *, const struct timespec *, int));
+int    _EXFUN(futimens, (int, const struct timespec *));
+#endif
+
+/* Provide prototypes for most of the _<systemcall> names that are
+   provided in newlib for some compilers.  */
+#ifdef _COMPILING_NEWLIB
+int    _EXFUN(_fstat,( int __fd, struct stat *__sbuf ));
+int    _EXFUN(_stat,( const char *__path, struct stat *__sbuf ));
+#ifdef __LARGE64_FILES
+struct stat64;
+int    _EXFUN(_fstat64,( int __fd, struct stat64 *__sbuf ));
+#endif
+#endif
+
+#endif /* !_STAT_H_ */
+#ifdef __cplusplus
+}
+#endif
+#endif /* _SYS_STAT_H */
index fdfc8ad..997fe9c 100644 (file)
Binary files a/user/parlib/newlib/lib/i386/libc.a and b/user/parlib/newlib/lib/i386/libc.a differ
index fdfc8ad..997fe9c 100644 (file)
Binary files a/user/parlib/newlib/lib/i386/libg.a and b/user/parlib/newlib/lib/i386/libg.a differ
index 863d5c5..f4e4f54 100644 (file)
Binary files a/user/parlib/newlib/lib/i386/libm.a and b/user/parlib/newlib/lib/i386/libm.a differ
index b6e5e4d..492075b 100644 (file)
@@ -134,7 +134,7 @@ int fstat(int file, struct stat *st)
                if (return_val == -1)
                        errno = result->err;
                else
-                       memcpy(st, (&result->st), sizeof(struct stat));
+                       memcpy(st, result->buf, sizeof(struct stat));
                        
                free(result);
        }
@@ -381,7 +381,7 @@ int read_from_channel(char * buf, int len, int peek)
        int total_read = 0;
 
        //int just_read = sys_serial_read(buf, len);
-       int just_read = sys_eth_read(buf, len);
+       int just_read = sys_serial_read(buf, len);
 
 
        if (just_read < 0) return just_read;
@@ -391,7 +391,7 @@ int read_from_channel(char * buf, int len, int peek)
 
        while (total_read != len) {
                //just_read = sys_serial_read(buf + total_read, len - total_read);
-               just_read = sys_eth_read(buf + total_read, len - total_read);
+               just_read = sys_serial_read(buf + total_read, len - total_read);
                
                if (just_read == -1) return -1;
                total_read += just_read;
@@ -466,21 +466,28 @@ response_t *send_message(char *msg, int len, syscall_id_t this_call_id)
        
        char* buffer = NULL;
 
-       if (this_call_id == READ_ID) 
+       if (   this_call_id == READ_ID 
+           || this_call_id == FSTAT_ID 
+           || this_call_id == STAT_ID)
        {
                if (ret_value < 0)
                        buffer_size = 0;
-               else
-                       buffer_size = ret_value;
+               else {
+                       if(this_call_id == READ_ID) 
+                               buffer_size = ret_value;
+                       else
+                               buffer_size = sizeof(struct stat);
+               }
                        
                return_response = malloc(sizeof(response_t) + buffer_size);
 
                if (return_response == NULL)
                        return NULL;
                
-               if (read_buffer_from_channel(return_response->buf, buffer_size) == -1)
+               if (read_buffer_from_channel(return_response->buf, buffer_size) == -1) {
+                       free(return_response);
                        return NULL;
-
+               }
        } 
        else 
        {
@@ -538,7 +545,7 @@ int stat(const char *file, struct stat *st)
                if (return_val == -1)
                        errno = result->err;
                else
-                       memcpy(st, &(result->st), sizeof(struct stat));
+                       memcpy(st, result->buf, sizeof(struct stat));
 
                free(result);
 
@@ -667,6 +674,6 @@ ssize_t write(int file, const void *ptr, size_t len)
 int write_to_channel(char * msg, int len)
 {
        //return sys_serial_write((char*)msg, len);
-       return sys_eth_write(msg, len);
+       return sys_serial_write(msg, len);
        
 }