Changeset 7171760 in mainline


Ignore:
Timestamp:
2011-08-18T12:05:00Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b33ec43
Parents:
866e627
Message:

Rework the way how open files are passed from parent task to child.

  • Instead of passing fdi_node_t's, pass handles directly using the IPC_M_STATE_CHANGE_AUTHORIZE mechanism.
  • Remove open_node(), fd_node(), fdi_node_t.
  • Replace fopen_node() with fopen_handle().
  • Replace fnode() with fhandle().
  • The child task does not synchronize with VFS yet.
Location:
uspace
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    r866e627 r7171760  
    100100        char *tmp;
    101101        int rc, retval, i;
    102         fdi_node_t file_nodes[3];
    103         fdi_node_t *file_nodes_p[4];
     102        int file_handles[3];
     103        int *file_handles_p[4];
    104104        FILE *files[3];
    105105
     
    112112       
    113113        for (i = 0; i < 3 && files[i] != NULL; i++) {
    114                 if (fnode(files[i], &file_nodes[i]) == EOK) {
    115                         file_nodes_p[i] = &file_nodes[i];
     114                if (fhandle(files[i], &file_handles[i]) == EOK) {
     115                        file_handles_p[i] = &file_handles[i];
    116116                }
    117117                else {
    118                         file_nodes_p[i] = NULL;
     118                        file_handles_p[i] = NULL;
    119119                }
    120120        }
    121         file_nodes_p[i] = NULL;
     121        file_handles_p[i] = NULL;
    122122
    123         rc = task_spawnvf(&tid, tmp, (const char **) argv, file_nodes_p);
     123        rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p);
    124124        free(tmp);
    125125
  • uspace/app/trace/trace.c

    r866e627 r7171760  
    587587
    588588        /* Send default files */
    589         fdi_node_t *files[4];
    590         fdi_node_t stdin_node;
    591         fdi_node_t stdout_node;
    592         fdi_node_t stderr_node;
    593        
    594         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    595                 files[0] = &stdin_node;
     589        int *files[4];
     590        int fd_stdin;
     591        int fd_stdout;
     592        int fd_stderr;
     593       
     594        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     595                files[0] = &fd_stdin;
    596596        else
    597597                files[0] = NULL;
    598598       
    599         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    600                 files[1] = &stdout_node;
     599        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     600                files[1] = &fd_stdout;
    601601        else
    602602                files[1] = NULL;
    603603       
    604         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    605                 files[2] = &stderr_node;
     604        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     605                files[2] = &fd_stderr;
    606606        else
    607607                files[2] = NULL;
     
    762762        o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
    763763        proto_add_oper(p, VFS_IN_OPEN, o);
    764         o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);
    765         proto_add_oper(p, VFS_IN_OPEN_NODE, o);
    766764        o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
    767765        proto_add_oper(p, VFS_IN_READ, o);
  • uspace/lib/c/generic/io/io.c

    r866e627 r7171760  
    101101static LIST_INITIALIZE(files);
    102102
    103 void __stdio_init(int filc, fdi_node_t *filv[])
     103void __stdio_init(int filc)
    104104{
    105105        if (filc > 0) {
    106                 stdin = fopen_node(filv[0], "r");
     106                stdin = fopen_handle(0);
    107107        } else {
    108108                stdin = &stdin_null;
     
    111111       
    112112        if (filc > 1) {
    113                 stdout = fopen_node(filv[1], "w");
     113                stdout = fopen_handle(1);
    114114        } else {
    115115                stdout = &stdout_klog;
     
    118118       
    119119        if (filc > 2) {
    120                 stderr = fopen_node(filv[2], "w");
     120                stderr = fopen_handle(2);
    121121        } else {
    122122                stderr = &stderr_klog;
     
    285285}
    286286
    287 FILE *fopen_node(fdi_node_t *node, const char *mode)
    288 {
    289         int flags;
    290         if (!parse_mode(mode, &flags))
    291                 return NULL;
    292        
     287FILE *fopen_handle(int fd)
     288{
    293289        /* Open file. */
    294290        FILE *stream = malloc(sizeof(FILE));
     
    298294        }
    299295       
    300         stream->fd = open_node(node, flags);
    301         if (stream->fd < 0) {
    302                 /* errno was set by open_node() */
    303                 free(stream);
    304                 return NULL;
    305         }
    306        
     296        stream->fd = fd;
    307297        stream->error = false;
    308298        stream->eof = false;
     
    780770}
    781771
    782 int fnode(FILE *stream, fdi_node_t *node)
    783 {
    784         if (stream->fd >= 0)
    785                 return fd_node(stream->fd, node);
     772int fhandle(FILE *stream, int *handle)
     773{
     774        if (stream->fd >= 0) {
     775                *handle = stream->fd;
     776                return EOK;
     777        }
    786778       
    787779        return ENOENT;
  • uspace/lib/c/generic/libc.c

    r866e627 r7171760  
    9191                argc = 0;
    9292                argv = NULL;
    93                 __stdio_init(0, NULL);
     93                __stdio_init(0);
    9494        } else {
    9595                argc = __pcb->argc;
    9696                argv = __pcb->argv;
    97                 __stdio_init(__pcb->filc, __pcb->filv);
     97                __stdio_init(__pcb->filc);
    9898                (void) chdir(__pcb->cwd);
    9999        }
  • uspace/lib/c/generic/loader.c

    r866e627 r7171760  
    256256 *
    257257 */
    258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[])
    259 {
    260         /*
    261          * Serialize the arguments into a single array. First
    262          * compute size of the buffer needed.
    263          */
    264         fdi_node_t *const *ap = files;
    265         size_t count = 0;
    266         while (*ap != NULL) {
    267                 count++;
    268                 ap++;
    269         }
    270        
    271         fdi_node_t *files_buf;
    272         files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t));
    273         if (files_buf == NULL)
    274                 return ENOMEM;
    275        
    276         /* Fill the buffer */
    277         size_t i;
    278         for (i = 0; i < count; i++)
    279                 files_buf[i] = *files[i];
    280        
     258int loader_set_files(loader_t *ldr, int * const files[])
     259{
    281260        /* Send serialized files to the loader */
    282261        async_exch_t *exch = async_exchange_begin(ldr->sess);
    283        
    284         ipc_call_t answer;
    285         aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer);
    286         sysarg_t rc = async_data_write_start(exch, (void *) files_buf,
    287             count * sizeof(fdi_node_t));
    288        
    289         async_exchange_end(exch);
    290         free(files_buf);
    291        
     262        async_exch_t *vfs_exch = vfs_exchange_begin();
     263       
     264        int i;
     265        for (i = 0; files[i]; i++)
     266                ;
     267
     268        ipc_call_t answer;
     269        aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer);
     270
     271        sysarg_t rc;
     272       
     273        for (i = 0; files[i]; i++) {
     274                rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i],
     275                    0, vfs_exch);
     276                if (rc != EOK)
     277                        break;
     278        }
     279       
     280        vfs_exchange_end(vfs_exch);
     281        async_exchange_end(exch);
     282
    292283        if (rc != EOK) {
    293284                async_wait_for(req, NULL);
  • uspace/lib/c/generic/private/async.h

    r866e627 r7171760  
    3636#define LIBC_PRIVATE_ASYNC_H_
    3737
     38#include <ipc/common.h>
    3839#include <adt/list.h>
    3940#include <fibril.h>
  • uspace/lib/c/generic/private/io.h

    r866e627 r7171760  
    3636#define LIBC_PRIVATE_IO_H_
    3737
    38 #include <vfs/vfs.h>
    39 
    40 extern void __stdio_init(int filc, fdi_node_t *filv[]);
     38extern void __stdio_init(int);
    4139extern void __stdio_done(void);
    4240
  • uspace/lib/c/generic/task.c

    r866e627 r7171760  
    103103{
    104104        /* Send default files */
    105         fdi_node_t *files[4];
    106         fdi_node_t stdin_node;
    107         fdi_node_t stdout_node;
    108         fdi_node_t stderr_node;
    109        
    110         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    111                 files[0] = &stdin_node;
     105        int *files[4];
     106        int fd_stdin;
     107        int fd_stdout;
     108        int fd_stderr;
     109       
     110        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     111                files[0] = &fd_stdin;
    112112        else
    113113                files[0] = NULL;
    114114       
    115         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    116                 files[1] = &stdout_node;
     115        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     116                files[1] = &fd_stdout;
    117117        else
    118118                files[1] = NULL;
    119119       
    120         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    121                 files[2] = &stderr_node;
     120        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     121                files[2] = &fd_stderr;
    122122        else
    123123                files[2] = NULL;
     
    143143 */
    144144int task_spawnvf(task_id_t *id, const char *path, const char *const args[],
    145     fdi_node_t *const files[])
     145    int *const files[])
    146146{
    147147        /* Connect to a program loader. */
  • uspace/lib/c/generic/vfs/vfs.c

    r866e627 r7171760  
    329329}
    330330
    331 int open_node(fdi_node_t *node, int oflag)
    332 {
    333         async_exch_t *exch = vfs_exchange_begin();
    334        
    335         ipc_call_t answer;
    336         aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,
    337             node->devmap_handle, node->index, oflag, &answer);
    338        
    339         vfs_exchange_end(exch);
    340 
    341         sysarg_t rc;
    342         async_wait_for(req, &rc);
    343        
    344         if (rc != EOK)
    345                 return (int) rc;
    346        
    347         return (int) IPC_GET_ARG1(answer);
    348 }
    349 
    350331int close(int fildes)
    351332{
     
    819800}
    820801
    821 int fd_node(int fildes, fdi_node_t *node)
    822 {
    823         struct stat stat;
    824         int rc = fstat(fildes, &stat);
    825        
    826         if (rc == EOK) {
    827                 node->fs_handle = stat.fs_handle;
    828                 node->devmap_handle = stat.devmap_handle;
    829                 node->index = stat.index;
    830         }
    831        
    832         return rc;
    833 }
    834 
    835802int dup2(int oldfd, int newfd)
    836803{
  • uspace/lib/c/include/loader/loader.h

    r866e627 r7171760  
    3939#include <task.h>
    4040
    41 typedef struct fdi_node fdi_node_t;
    42 
    4341/** Forward declararion */
    4442struct loader;
     
    5149extern int loader_set_pathname(loader_t *, const char *);
    5250extern int loader_set_args(loader_t *, const char *const[]);
    53 extern int loader_set_files(loader_t *, fdi_node_t *const[]);
     51extern int loader_set_files(loader_t *, int *const[]);
    5452extern int loader_load_program(loader_t *);
    5553extern int loader_run(loader_t *);
  • uspace/lib/c/include/loader/pcb.h

    r866e627 r7171760  
    3838
    3939#include <sys/types.h>
    40 #include <vfs/vfs.h>
    4140
    4241typedef void (*entry_point_t)(void);
     
    6261       
    6362        /** Number of preset files. */
    64         int filc;
    65         /** Preset files. */
    66         fdi_node_t **filv;
     63        unsigned int filc;
    6764       
    6865        /*
  • uspace/lib/c/include/task.h

    r866e627 r7171760  
    3838#include <sys/types.h>
    3939
    40 typedef struct fdi_node fdi_node_t;
    41 
    4240typedef uint64_t task_id_t;
    4341
     
    5452extern int task_spawnv(task_id_t *, const char *path, const char *const []);
    5553extern int task_spawnvf(task_id_t *, const char *path, const char *const [],
    56     fdi_node_t *const []);
     54    int *const []);
    5755extern int task_spawnl(task_id_t *, const char *path, ...);
    5856
  • uspace/lib/c/include/vfs/vfs.h

    r866e627 r7171760  
    4646};
    4747
    48 /** Libc version of the VFS triplet.
    49  *
    50  * Unique identification of a file system node
    51  * within a file system instance.
    52  *
    53  */
    54 typedef struct fdi_node {
    55         fs_handle_t fs_handle;
    56         devmap_handle_t devmap_handle;
    57         fs_index_t index;
    58 } fdi_node_t;
    59 
    6048extern char *absolutize(const char *, size_t *);
    6149
     
    6452extern int unmount(const char *);
    6553
    66 extern int open_node(fdi_node_t *, int);
    67 extern int fd_node(int, fdi_node_t *);
    68 
    69 extern FILE *fopen_node(fdi_node_t *, const char *);
    70 extern int fnode(FILE *, fdi_node_t *);
     54extern FILE *fopen_handle(int);
     55extern int fhandle(FILE *, int *);
    7156
    7257extern async_exch_t *vfs_exchange_begin(void);
  • uspace/srv/loader/main.c

    r866e627 r7171760  
    6161#include <elf/elf.h>
    6262#include <elf/elf_load.h>
     63#include <vfs/vfs.h>
    6364
    6465#ifdef CONFIG_RTLD
     
    8990
    9091/** Number of preset files */
    91 static int filc = 0;
    92 /** Preset files vector */
    93 static fdi_node_t **filv = NULL;
    94 /** Buffer holding all preset files */
    95 static fdi_node_t *fil_buf = NULL;
     92static unsigned int filc = 0;
    9693
    9794static elf_info_t prog_info;
     
    239236static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    240237{
    241         fdi_node_t *buf;
    242         size_t buf_size;
    243         int rc = async_data_write_accept((void **) &buf, false, 0, 0,
    244             sizeof(fdi_node_t), &buf_size);
    245        
    246         if (rc == EOK) {
    247                 int count = buf_size / sizeof(fdi_node_t);
    248                
    249                 /*
    250                  * Allocate new filv
    251                  */
    252                 fdi_node_t **_filv = (fdi_node_t **) calloc(count + 1, sizeof(fdi_node_t *));
    253                 if (_filv == NULL) {
    254                         free(buf);
    255                         async_answer_0(rid, ENOMEM);
    256                         return;
     238        size_t count = IPC_GET_ARG1(*request);
     239
     240        async_exch_t *vfs_exch = vfs_exchange_begin();
     241
     242        for (filc = 0; filc < count; filc++) {
     243                ipc_callid_t callid;
     244
     245                if (!async_state_change_receive(&callid, NULL, NULL, NULL)) {
     246                        async_answer_0(callid, EINVAL);
     247                        break;
    257248                }
    258                
    259                 /*
    260                  * Fill the new filv with argument pointers
    261                  */
    262                 int i;
    263                 for (i = 0; i < count; i++)
    264                         _filv[i] = &buf[i];
    265                
    266                 _filv[count] = NULL;
    267                
    268                 /*
    269                  * Copy temporary data to global variables
    270                  */
    271                 if (fil_buf != NULL)
    272                         free(fil_buf);
    273                
    274                 if (filv != NULL)
    275                         free(filv);
    276                
    277                 filc = count;
    278                 fil_buf = buf;
    279                 filv = _filv;
    280         }
    281        
     249                async_state_change_finalize(callid, vfs_exch);
     250        }
     251
     252        vfs_exchange_end(vfs_exch);
     253
    282254        async_answer_0(rid, EOK);
    283255}
     
    308280       
    309281        pcb.filc = filc;
    310         pcb.filv = filv;
    311282       
    312283        if (prog_info.interp == NULL) {
Note: See TracChangeset for help on using the changeset viewer.