Changeset b0f00a9 in mainline for uspace/app


Ignore:
Timestamp:
2011-11-06T22:21:05Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
898e847
Parents:
2bdf8313 (diff), 7b5f4c9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/app
Files:
276 added
5 deleted
83 edited
7 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    r2bdf8313 rb0f00a9  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \
    33         -Icmds/builtins -Icmds/modules
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \
     32        $(LIBFMTUTIL_PREFIX)/libfmtutil.a
     33EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) \
     34        -I$(LIBFMTUTIL_PREFIX) -I. -Icmds/ -Icmds/builtins -Icmds/modules
    3435BINARY = bdsh
    3536
     
    5051        cmds/modules/unmount/unmount.c \
    5152        cmds/modules/kcon/kcon.c \
     53        cmds/builtins/batch/batch.c \
    5254        cmds/builtins/exit/exit.c \
    5355        cmds/builtins/cd/cd.c \
    5456        cmds/mod_cmds.c \
    5557        cmds/builtin_cmds.c \
     58        compl.c \
    5659        errors.c \
    5760        input.c \
    5861        util.c \
    5962        exec.c \
    60         scli.c
     63        scli.c \
     64        tok.c
    6165
    6266include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/bdsh/cmds/builtin_cmds.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    3836#include "cmds.h"
    3937#include "builtin_aliases.h"
     38#include "scli.h"
    4039
    4140extern volatile unsigned int cli_interactive;
     
    9796                cmd->help(extended);
    9897                return CL_EOK;
    99         } else
     98        } else {
    10099                return CL_ENOENT;
     100        }
    101101}
    102102
    103 int run_builtin(int builtin, char *argv[], cliuser_t *usr)
     103int run_builtin(int builtin, char *argv[], cliuser_t *usr, iostate_t *new_iostate)
    104104{
     105        int rc;
    105106        builtin_t *cmd = builtins;
    106107
    107108        cmd += builtin;
     109       
     110        iostate_t *old_iostate = get_iostate();
     111        set_iostate(new_iostate);
     112       
     113        if (NULL != cmd->entry) {
     114                rc = ((int)cmd->entry(argv, usr));
     115        } else {
     116                rc = CL_ENOENT;
     117        }
     118       
     119        set_iostate(old_iostate);
    108120
    109         if (NULL != cmd->entry)
    110                 return((int)cmd->entry(argv, usr));
    111 
    112         return CL_ENOENT;
     121        return rc;
    113122}
  • uspace/app/bdsh/cmds/builtins/builtins.h

    r2bdf8313 rb0f00a9  
    44#include "config.h"
    55
     6#include "batch/entry.h"
    67#include "cd/entry.h"
    78#include "exit/entry.h"
    89
    910builtin_t builtins[] = {
     11#include "batch/batch_def.h"
    1012#include "cd/cd_def.h"
    1113#include "exit/exit_def.h"
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
  • uspace/app/bdsh/cmds/builtins/exit/exit.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
  • uspace/app/bdsh/cmds/cmds.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef CMDS_H
    230#define CMDS_H
     
    5987extern char *alias_for_module(const char *);
    6088extern int help_module(int, unsigned int);
    61 extern int run_module(int, char *[]);
     89extern int run_module(int, char *[], iostate_t *);
    6290
    6391/* Prototypes for builtin launchers */
     
    6795extern char *alias_for_builtin(const char *);
    6896extern int help_builtin(int, unsigned int);
    69 extern int run_builtin(int, char *[], cliuser_t *);
     97extern int run_builtin(int, char *[], cliuser_t *, iostate_t *);
    7098
    7199#endif
  • uspace/app/bdsh/cmds/mod_cmds.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    118116                mod->help(extended);
    119117                return CL_EOK;
    120         } else
     118        } else {
    121119                return CL_ENOENT;
     120        }
    122121}
    123122
    124123/* Invokes the module entry point modules[module], passing argv[] as an argument
    125124 * stack. */
    126 int run_module(int module, char *argv[])
     125int run_module(int module, char *argv[], iostate_t *new_iostate)
    127126{
     127        int rc;
    128128        module_t *mod = modules;
    129129
    130130        mod += module;
     131       
     132        iostate_t *old_iostate = get_iostate();
     133        set_iostate(new_iostate);
    131134
    132         if (NULL != mod->entry)
    133                 return ((int)mod->entry(argv));
     135        if (NULL != mod->entry) {
     136                rc = ((int)mod->entry(argv));
     137        } else {
     138                rc = CL_ENOENT;
     139        }
     140       
     141        set_iostate(old_iostate);
    134142
    135         return CL_ENOENT;
     143        return rc;
    136144}
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    r2bdf8313 rb0f00a9  
    3939
    4040#include <libblock.h>
    41 #include <devmap.h>
     41#include <loc.h>
    4242#include <errno.h>
    4343#include <assert.h>
     
    6969        unsigned int argc;
    7070        unsigned int i, j;
    71         devmap_handle_t handle;
     71        service_id_t service_id;
    7272        aoff64_t offset;
    7373        uint8_t *blk;
     
    9696                size = 256;
    9797
    98         rc = devmap_device_get_handle(argv[1], &handle, 0);
     98        rc = loc_service_get_id(argv[1], &service_id, 0);
    9999        if (rc != EOK) {
    100100                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
     
    102102        }
    103103
    104         rc = block_init(handle, 2048);
     104        rc = block_init(EXCHANGE_SERIALIZE, service_id, 2048);
    105105        if (rc != EOK)  {
    106106                printf("%s: Error initializing libblock.\n", cmdname);
     
    108108        }
    109109
    110         rc = block_get_bsize(handle, &block_size);
     110        rc = block_get_bsize(service_id, &block_size);
    111111        if (rc != EOK) {
    112112                printf("%s: Error determining device block size.\n", cmdname);
     
    117117        if (blk == NULL) {
    118118                printf("%s: Error allocating memory.\n", cmdname);
    119                 block_fini(handle);
     119                block_fini(service_id);
    120120                return CMD_FAILURE;
    121121        }
     
    124124
    125125        while (size > 0) {
    126                 rc = block_read_direct(handle, ba, 1, blk);
     126                rc = block_read_direct(service_id, ba, 1, blk);
    127127                if (rc != EOK) {
    128128                        printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba);
    129129                        free(blk);
    130                         block_fini(handle);
     130                        block_fini(service_id);
    131131                        return CMD_FAILURE;
    132132                }
     
    170170
    171171        free(blk);
    172         block_fini(handle);
     172        block_fini(service_id);
    173173
    174174        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * Copyright (c) 2011, Martin Sucha
    34 * All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions are met:
     7 * modification, are permitted provided that the following conditions
     8 * are met:
    79 *
    8  * Redistributions of source code must retain the above copyright notice, this
    9  * list of conditions and the following disclaimer.
     10 * - Redistributions of source code must retain the above copyright
     11 *   notice, this list of conditions and the following disclaimer.
     12 * - Redistributions in binary form must reproduce the above copyright
     13 *   notice, this list of conditions and the following disclaimer in the
     14 *   documentation and/or other materials provided with the distribution.
     15 * - The name of the author may not be used to endorse or promote products
     16 *   derived from this software without specific prior written permission.
    1017 *
    11  * Redistributions in binary form must reproduce the above copyright notice,
    12  * this list of conditions and the following disclaimer in the documentation
    13  * and/or other materials provided with the distribution.
    14  *
    15  * Neither the name of the original program's authors nor the names of its
    16  * contributors may be used to endorse or promote products derived from this
    17  * software without specific prior written permission.
    18  *
    19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    29  * POSSIBILITY OF SUCH DAMAGE.
     18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3028 */
    3129
     
    6462static sysarg_t console_rows = 0;
    6563static bool should_quit = false;
     64
     65static console_ctrl_t *console = NULL;
    6666
    6767static struct option const long_options[] = {
     
    102102static void waitprompt()
    103103{
    104         console_set_pos(fphone(stdout), 0, console_rows-1);
    105         console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0);
     104        console_set_pos(console, 0, console_rows-1);
     105        console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0);
     106       
    106107        printf("ENTER/SPACE/PAGE DOWN - next page, "
    107108               "ESC/Q - quit, C - continue unpaged");
    108109        fflush(stdout);
    109         console_set_style(fphone(stdout), STYLE_NORMAL);
     110       
     111        console_set_style(console, STYLE_NORMAL);
    110112}
    111113
    112114static void waitkey()
    113115{
    114         console_event_t ev;
     116        kbd_event_t ev;
    115117       
    116118        while (true) {
    117                 if (!console_get_event(fphone(stdin), &ev)) {
     119                if (!console_get_kbd_event(console, &ev)) {
    118120                        return;
    119121                }
     
    138140static void newpage()
    139141{
    140         console_clear(fphone(stdout));
     142        console_clear(console);
    141143        chars_remaining = console_cols;
    142         lines_remaining = console_rows-1;
     144        lines_remaining = console_rows - 1;
    143145}
    144146
     
    238240        console_rows = 0;
    239241        should_quit = false;
     242        console = console_init(stdin, stdout);
    240243
    241244        argc = cli_count_args(argv);
     
    280283       
    281284        if (more) {
    282                 rc = console_get_size(fphone(stdout), &cols, &rows);
     285                rc = console_get_size(console, &cols, &rows);
    283286                if (rc != EOK) {
    284287                        printf("%s - cannot get console size\n", cmdname);
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
    6  *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
    9  *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    3533#include <str.h>
    3634#include <fcntl.h>
     35#include <sys/stat.h>
     36#include <dirent.h>
    3737#include "config.h"
    3838#include "util.h"
     
    5757};
    5858
     59typedef enum {
     60        TYPE_NONE,
     61        TYPE_FILE,
     62        TYPE_DIR
     63} dentry_type_t;
     64
     65static int64_t copy_file(const char *src, const char *dest,
     66    size_t blen, int vb);
     67
     68/** Get the type of a directory entry.
     69 *
     70 * @param path  Path of the directory entry.
     71 *
     72 * @return TYPE_DIR if the dentry is a directory.
     73 * @return TYPE_FILE if the dentry is a file.
     74 * @return TYPE_NONE if the dentry does not exists.
     75 */
     76static dentry_type_t get_type(const char *path)
     77{
     78        struct stat s;
     79
     80        int r = stat(path, &s);
     81
     82        if (r)
     83                return TYPE_NONE;
     84        else if (s.is_directory)
     85                return TYPE_DIR;
     86        else if (s.is_file)
     87                return TYPE_FILE;
     88
     89        return TYPE_NONE;
     90}
     91
    5992static int strtoint(const char *s1)
    6093{
     
    70103}
    71104
     105/** Get the last component of a path.
     106 *
     107 * e.g. /data/a  ---> a
     108 *
     109 * @param path  Pointer to the path.
     110 *
     111 * @return      Pointer to the last component or to the path itself.
     112 */
     113static char *get_last_path_component(char *path)
     114{
     115        char *ptr;
     116
     117        ptr = str_rchr(path, '/');
     118        if (!ptr)
     119                return path;
     120        else
     121                return ptr + 1;
     122}
     123
     124/** Merge two paths together.
     125 *
     126 * e.g. (path1 = /data/dir, path2 = a/b) --> /data/dir/a/b
     127 *
     128 * @param path1         Path to which path2 will be appended.
     129 * @param path1_size    Size of the path1 buffer.
     130 * @param path2         Path that will be appended to path1.
     131 */
     132static void merge_paths(char *path1, size_t path1_size, char *path2)
     133{
     134        const char *delim = "/";
     135
     136        str_rtrim(path1, '/');
     137        str_append(path1, path1_size, delim);
     138        str_append(path1, path1_size, path2);
     139}
     140
     141static int64_t do_copy(const char *src, const char *dest,
     142    size_t blen, int vb, int recursive, int force)
     143{
     144        int r = -1;
     145        char dest_path[PATH_MAX];
     146        char src_path[PATH_MAX];
     147        DIR *dir = NULL;
     148        struct dirent *dp;
     149
     150        dentry_type_t src_type = get_type(src);
     151        dentry_type_t dest_type = get_type(dest);
     152
     153        const size_t src_len = str_size(src);
     154
     155        if (src_type == TYPE_FILE) {
     156                char *src_fname;
     157
     158                /* Initialize the src_path with the src argument */
     159                str_cpy(src_path, src_len + 1, src);
     160                str_rtrim(src_path, '/');
     161               
     162                /* Get the last component name from the src path */
     163                src_fname = get_last_path_component(src_path);
     164               
     165                /* Initialize dest_path with the dest argument */
     166                str_cpy(dest_path, PATH_MAX, dest);
     167
     168                if (dest_type == TYPE_DIR) {
     169                        /* e.g. cp file_name /data */
     170                        /* e.g. cp file_name /data/ */
     171                       
     172                        /* dest is a directory,
     173                         * append the src filename to it.
     174                         */
     175                        merge_paths(dest_path, PATH_MAX, src_fname);
     176                        dest_type = get_type(dest_path);
     177                } else if (dest_type == TYPE_NONE) {
     178                        if (dest_path[str_size(dest_path) - 1] == '/') {
     179                                /* e.g. cp /textdemo /data/dirnotexists/ */
     180
     181                                printf("The dest directory %s does not exists",
     182                                    dest_path);
     183                                goto exit;
     184                        }
     185                }
     186
     187                if (dest_type == TYPE_DIR) {
     188                        printf("Cannot overwrite existing directory %s\n",
     189                            dest_path);
     190                        goto exit;
     191                } else if (dest_type == TYPE_FILE) {
     192                        /* e.g. cp file_name existing_file */
     193
     194                        /* dest already exists, if force is set we will
     195                         * try to remove it.
     196                         */
     197                        if (force) {
     198                                if (unlink(dest_path)) {
     199                                        printf("Unable to remove %s\n",
     200                                            dest_path);
     201                                        goto exit;
     202                                }
     203                        } else {
     204                                printf("file already exists: %s\n", dest_path);
     205                                goto exit;
     206                        }
     207                }
     208
     209                /* call copy_file and exit */
     210                r = (copy_file(src, dest_path, blen, vb) < 0);
     211
     212        } else if (src_type == TYPE_DIR) {
     213                /* e.g. cp -r /x/srcdir /y/destdir/ */
     214
     215                if (!recursive) {
     216                        printf("Cannot copy the %s directory without the "
     217                            "-r option\n", src);
     218                        goto exit;
     219                } else if (dest_type == TYPE_FILE) {
     220                        printf("Cannot overwrite a file with a directory\n");
     221                        goto exit;
     222                }
     223
     224                char *src_dirname;
     225
     226                /* Initialize src_path with the content of src */
     227                str_cpy(src_path, src_len + 1, src);
     228                str_rtrim(src_path, '/');
     229
     230                src_dirname = get_last_path_component(src_path);
     231
     232                str_cpy(dest_path, PATH_MAX, dest);
     233
     234                switch (dest_type) {
     235                case TYPE_DIR:
     236                        if (str_cmp(src_dirname, "..") &&
     237                            str_cmp(src_dirname, ".")) {
     238                                /* The last component of src_path is
     239                                 * not '.' or '..'
     240                                 */
     241                                merge_paths(dest_path, PATH_MAX, src_dirname);
     242
     243                                if (mkdir(dest_path, 0) == -1) {
     244                                        printf("Unable to create "
     245                                            "dest directory %s\n", dest_path);
     246                                        goto exit;
     247                                }
     248                        }
     249                        break;
     250                default:
     251                case TYPE_NONE:
     252                        /* dest does not exists, this means the user wants
     253                         * to specify the name of the destination directory
     254                         *
     255                         * e.g. cp -r /src /data/new_dir_src
     256                         */
     257                        if (mkdir(dest_path, 0)) {
     258                                printf("Unable to create "
     259                                    "dest directory %s\n", dest_path);
     260                                goto exit;
     261                        }
     262                        break;
     263                }
     264
     265                dir = opendir(src);
     266                if (!dir) {
     267                        /* Something strange is happening... */
     268                        printf("Unable to open src %s directory\n", src);
     269                        goto exit;
     270                }
     271
     272                /* Copy every single directory entry of src into the
     273                 * destination directory.
     274                 */
     275                while ((dp = readdir(dir))) {
     276                        struct stat src_s;
     277                        struct stat dest_s;
     278
     279                        char src_dent[PATH_MAX];
     280                        char dest_dent[PATH_MAX];
     281
     282                        str_cpy(src_dent, PATH_MAX, src);
     283                        merge_paths(src_dent, PATH_MAX, dp->d_name);
     284
     285                        str_cpy(dest_dent, PATH_MAX, dest_path);
     286                        merge_paths(dest_dent, PATH_MAX, dp->d_name);
     287
     288                        /* Check if we are copying a directory into itself */
     289                        stat(src_dent, &src_s);
     290                        stat(dest_path, &dest_s);
     291
     292                        if (dest_s.index == src_s.index &&
     293                            dest_s.fs_handle == src_s.fs_handle) {
     294                                printf("Cannot copy a directory "
     295                                    "into itself\n");
     296                                goto exit;
     297                        }
     298
     299                        if (vb)
     300                                printf("copy %s %s\n", src_dent, dest_dent);
     301
     302                        /* Recursively call do_copy() */
     303                        r = do_copy(src_dent, dest_dent, blen, vb, recursive,
     304                            force);
     305                        if (r)
     306                                goto exit;
     307
     308                }
     309        } else
     310                printf("Unable to open source file %s\n", src);
     311
     312exit:
     313        if (dir)
     314                closedir(dir);
     315        return r;
     316}
     317
     318
    72319static int64_t copy_file(const char *src, const char *dest,
    73320        size_t blen, int vb)
    74321{
    75         int fd1, fd2, bytes = 0;
    76         off64_t total = 0;
     322        int fd1, fd2, bytes;
     323        off64_t total;
    77324        int64_t copied = 0;
    78325        char *buff = NULL;
     
    106353        }
    107354
    108         for (;;) {
    109                 ssize_t res;
    110                 size_t written = 0;
    111 
    112                 bytes = read(fd1, buff, blen);
    113                 if (bytes <= 0)
     355        while ((bytes = read_all(fd1, buff, blen)) > 0) {
     356                if ((bytes = write_all(fd2, buff, bytes)) < 0)
    114357                        break;
    115358                copied += bytes;
    116                 res = bytes;
    117                 do {
    118                         /*
    119                          * Theoretically, it may not be enough to call write()
    120                          * only once. Also the previous read() may have
    121                          * returned less data than requested.
    122                          */
    123                         bytes = write(fd2, buff + written, res);
    124                         if (bytes < 0)
    125                                 goto err;
    126                         written += bytes;
    127                         res -= bytes;
    128                 } while (res > 0);
    129 
    130                 /* TODO: re-insert assert() once this is stand alone,
    131                  * removed as abort() exits the entire shell
    132                  */
    133                 if (res != 0) {
    134                         printf("\n%zd more bytes than actually exist were copied\n", res);
    135                         goto err;
    136                 }
    137359        }
    138360
    139361        if (bytes < 0) {
    140 err:
    141362                printf("\nError copying %s, (%d)\n", src, bytes);
    142363                copied = bytes;
     
    155376        static char helpfmt[] =
    156377            "Usage:  %s [options] <source> <dest>\n"
    157             "Options: (* indicates not yet implemented)\n"
     378            "Options:\n"
    158379            "  -h, --help       A short option summary\n"
    159380            "  -v, --version    Print version information and exit\n"
    160             "* -V, --verbose    Be annoyingly noisy about what's being done\n"
    161             "* -f, --force      Do not complain when <dest> exists\n"
    162             "* -r, --recursive  Copy entire directories\n"
    163             "  -b, --buffer ## Set the read buffer size to ##\n"
    164             "Currently, %s is under development, some options may not work.\n";
     381            "  -V, --verbose    Be annoyingly noisy about what's being done\n"
     382            "  -f, --force      Do not complain when <dest> exists\n"
     383            "  -r, --recursive  Copy entire directories\n"
     384            "  -b, --buffer ## Set the read buffer size to ##\n";
    165385        if (level == HELP_SHORT) {
    166386                printf("`%s' copies files and directories\n", cmdname);
    167387        } else {
    168388                help_cmd_cp(HELP_SHORT);
    169                 printf(helpfmt, cmdname, cmdname);
     389                printf(helpfmt, cmdname);
    170390        }
    171391
     
    176396{
    177397        unsigned int argc, verbose = 0;
    178         int buffer = 0;
     398        int buffer = 0, recursive = 0;
     399        int force = 0;
    179400        int c, opt_ind;
    180401        int64_t ret;
     
    195416                        break;
    196417                case 'f':
     418                        force = 1;
    197419                        break;
    198420                case 'r':
     421                        recursive = 1;
    199422                        break;
    200423                case 'b':
     
    222445        }
    223446
    224         ret = copy_file(argv[optind], argv[optind + 1], buffer, verbose);
    225 
    226         if (verbose)
    227                 printf("%" PRId64 " bytes copied\n", ret);
    228 
    229         if (ret >= 0)
     447        ret = do_copy(argv[optind], argv[optind + 1], buffer, verbose,
     448            recursive, force);
     449
     450        if (ret == 0)
    230451                return CMD_SUCCESS;
    231452        else
  • uspace/app/bdsh/cmds/modules/help/help.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2011 Martin Sucha
    24 * All rights reserved.
    35 *
    46 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     7 * modification, are permitted provided that the following conditions
     8 * are met:
    69 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     10 * - Redistributions of source code must retain the above copyright
     11 *   notice, this list of conditions and the following disclaimer.
     12 * - Redistributions in binary form must reproduce the above copyright
     13 *   notice, this list of conditions and the following disclaimer in the
     14 *   documentation and/or other materials provided with the distribution.
     15 * - The name of the author may not be used to endorse or promote products
     16 *   derived from this software without specific prior written permission.
    917 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2928 */
    3029
     
    3231#include <stdlib.h>
    3332#include <str.h>
     33#include <fmtutil.h>
    3434
    3535#include "config.h"
     
    130130static void help_survival(void)
    131131{
    132         printf("Don't panic!\n\n");
    133 
    134         printf("This is Bdsh, the Brain dead shell, currently "
     132        print_wrapped_console(
     133            "Don't panic!\n\n"
     134
     135            "This is Bdsh, the Brain dead shell, currently "
    135136            "the primary user interface to HelenOS. Bdsh allows you to enter "
    136137            "commands and supports history (Up, Down arrow keys), "
    137138            "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
    138139            "selection (Shift + movement keys), copy and paste (Ctrl-C, "
    139             "Ctrl-V), similar to common desktop environments.\n\n");
    140 
    141         printf("The most basic filesystem commands are Bdsh builtins. Type "
     140            "Ctrl-V), similar to common desktop environments.\n\n"
     141
     142            "The most basic filesystem commands are Bdsh builtins. Type "
    142143            "'help commands' [Enter] to see the list of Bdsh builtin commands. "
    143144            "Other commands are external executables located in the /app and "
    144145            "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
    145146            "to see their list. You can execute an external command simply "
    146             "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
    147 
    148         printf("HelenOS has virtual consoles (VCs). You can switch between "
    149             "these using the F1-F11 keys.\n\n");
    150 
    151         printf("This is but a small glimpse of what you can do with HelenOS. "
     147            "by entering its name (e.g. type 'tetris' [Enter]).\n\n"
     148
     149            "HelenOS has virtual consoles (VCs). You can switch between "
     150            "these using the F1-F11 keys.\n\n"
     151
     152            "This is but a small glimpse of what you can do with HelenOS. "
    152153            "To learn more please point your browser to the HelenOS User's "
    153             "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
     154            "Guide: http://trac.helenos.org/wiki/UsersGuide\n\n",
     155            ALIGN_LEFT);
    154156}
    155157
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    3230#include <stdlib.h>
    3331#include <io/console.h>
    34 #include <vfs/vfs.h>
    3532#include "config.h"
    3633#include "util.h"
     
    4239static const char *cmdname = "kcon";
    4340
    44 /* Dispays help for kcon in various levels */
     41/* Display help for kcon in various levels */
    4542void help_cmd_kcon(unsigned int level)
    4643{
    4744        printf("`kcon' switches to the kernel debug console.\n");
    48 
    49         if (level != HELP_SHORT) {
    50                 printf("Usage:  %s\n", cmdname);
    51         }
    52 
     45       
     46        if (level != HELP_SHORT)
     47                printf("Usage: %s\n", cmdname);
     48       
    5349        return;
    5450}
     
    5753int cmd_kcon(char **argv)
    5854{
    59         unsigned int argc;
    60 
    61         argc = cli_count_args(argv);
    62 
     55        unsigned int argc = cli_count_args(argv);
     56       
    6357        if (argc != 1) {
    6458                printf("%s - incorrect number of arguments. Try `%s --help'\n",
    65                         cmdname, cmdname);
     59                    cmdname, cmdname);
    6660                return CMD_FAILURE;
    6761        }
    68 
    69         console_kcon_enable(fphone(stdout));
    70 
    71         return CMD_SUCCESS;
     62       
     63        if (console_kcon())
     64                return CMD_SUCCESS;
     65        else
     66                return CMD_FAILURE;
    7267}
    73 
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
    6  *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
    9  *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    171169               
    172170                /* fill the name field */
    173                 tosort[nbdirs].name = (char *) malloc(str_length(dp->d_name) + 1);
     171                tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1);
    174172                if (!tosort[nbdirs].name) {
    175173                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
    176174                        goto out;
    177175                }
    178                
    179                 str_cpy(tosort[nbdirs].name, str_length(dp->d_name) + 1, dp->d_name);
     176
     177                str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name);
    180178                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
    181179                buff[len] = '\0';
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    30 
    3128
    3229#include <stdio.h>
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r2bdf8313 rb0f00a9  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    2928
    3029#include <stdio.h>
     
    5554static struct option const long_options[] = {
    5655        {"size", required_argument, 0, 's'},
     56        {"sparse", no_argument, 0, 'p'},
    5757        {"help", no_argument, 0, 'h'},
    5858        {0, 0, 0, 0}
     
    7070                "  -h, --help       A short option summary\n"
    7171                "  -s, --size sz    Size of the file\n"
     72                "  -p, --sparse     Create a sparse file\n"
    7273                "\n"
    7374                "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n"
     
    116117        ssize_t file_size;
    117118        ssize_t total_written;
    118         ssize_t to_write, rc;
     119        ssize_t to_write, rc, rc2 = 0;
    119120        char *file_name;
    120121        void *buffer;
     122        bool create_sparse = false;
    121123
    122124        file_size = 0;
     
    125127
    126128        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    127                 c = getopt_long(argc, argv, "s:h", long_options, &opt_ind);
     129                c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind);
    128130                switch (c) {
    129131                case 'h':
    130132                        help_cmd_mkfile(HELP_LONG);
    131133                        return CMD_SUCCESS;
     134                case 'p':
     135                        create_sparse = true;
     136                        break;
    132137                case 's':
    133138                        file_size = read_size(optarg);
     
    155160                printf("%s: failed to create file %s.\n", cmdname, file_name);
    156161                return CMD_FAILURE;
     162        }
     163
     164        if (create_sparse && file_size > 0) {
     165                const char byte = 0x00;
     166
     167                if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
     168                        goto exit;
     169
     170                rc2 = write(fd, &byte, sizeof(char));
     171                goto exit;
    157172        }
    158173
     
    175190        }
    176191
     192        free(buffer);
     193exit:
    177194        rc = close(fd);
    178         if (rc != 0) {
     195
     196        if (rc != 0 || rc2 < 0) {
    179197                printf("%s: Error writing file (%zd).\n", cmdname, rc);
    180198                return CMD_FAILURE;
    181199        }
    182 
    183         free(buffer);
    184200
    185201        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/module_aliases.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef MODULE_ALIASES_H
    230#define MODULE_ALIASES_H
  • uspace/app/bdsh/cmds/modules/modules.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef MODULES_H
    230#define MODULES_H
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    r2bdf8313 rb0f00a9  
    3030#include <stdlib.h>
    3131#include <vfs/vfs.h>
     32#include <adt/list.h>
    3233#include <errno.h>
    3334#include <getopt.h>
     35#include <inttypes.h>
    3436#include "config.h"
    3537#include "util.h"
     
    4345static struct option const long_options[] = {
    4446        { "help", no_argument, 0, 'h' },
     47        { "instance", required_argument, 0, 'i' },
    4548        { 0, 0, 0, 0 }
    4649};
     
    5154{
    5255        static char helpfmt[] =
    53             "Usage:  %s <fstype> <mp> <dev> [<moptions>]\n";
     56            "Usage:  %s <fstype> <mp> [dev] [<moptions>]\n";
    5457        if (level == HELP_SHORT) {
    5558                printf("'%s' mounts a file system.\n", cmdname);
     
    6164}
    6265
     66static void print_mtab_list(void)
     67{
     68        LIST_INITIALIZE(mtab_list);
     69        get_mtab_list(&mtab_list);
     70
     71        mtab_ent_t *old_ent = NULL;
     72
     73        list_foreach(mtab_list, cur) {
     74                mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
     75                    link);
     76
     77                if (old_ent)
     78                        free(old_ent);
     79
     80                old_ent = mtab_ent;
     81
     82                printf("%s", mtab_ent->fs_name);
     83                if (mtab_ent->instance)
     84                        printf("/%d", mtab_ent->instance);
     85                printf(" on %s ", mtab_ent->mp);
     86
     87                if (str_size(mtab_ent->opts) > 0)
     88                        printf("opts=%s ", mtab_ent->opts);
     89
     90                printf("(service=%" PRIun ")\n", mtab_ent->service_id);
     91        }
     92
     93        if (old_ent)
     94                free(old_ent);
     95}
     96
    6397/* Main entry point for mount, accepts an array of arguments */
    6498int cmd_mount(char **argv)
     
    66100        unsigned int argc;
    67101        const char *mopts = "";
     102        const char *dev = "";
    68103        int rc, c, opt_ind;
     104        unsigned int instance = 0;
     105        bool instance_set = false;
     106        char **t_argv;
    69107
    70108        argc = cli_count_args(argv);
    71109
    72110        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    73                 c = getopt_long(argc, argv, "h", long_options, &opt_ind);
     111                c = getopt_long(argc, argv, "i:h", long_options, &opt_ind);
    74112                switch (c) {
    75113                case 'h':
    76114                        help_cmd_mount(HELP_LONG);
    77115                        return CMD_SUCCESS;
     116                case 'i':
     117                        instance = (unsigned int) strtol(optarg, NULL, 10);
     118                        instance_set = true;
     119                        break;
    78120                }
    79121        }
    80122
    81         if ((argc < 4) || (argc > 5)) {
     123        if (instance_set) {
     124                argc -= 2;
     125                t_argv = &argv[2];
     126        } else
     127                t_argv = &argv[0];
     128
     129        if ((argc == 2) || (argc > 5)) {
    82130                printf("%s: invalid number of arguments. Try `mount --help'\n",
    83131                    cmdname);
    84132                return CMD_FAILURE;
    85133        }
     134        if (argc == 1) {
     135                print_mtab_list();
     136                return CMD_SUCCESS;
     137        }
     138        if (argc > 3)
     139                dev = t_argv[3];
    86140        if (argc == 5)
    87                 mopts = argv[4];
     141                mopts = t_argv[4];
    88142
    89         rc = mount(argv[1], argv[2], argv[3], mopts, 0);
     143        rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
    90144        if (rc != EOK) {
    91145                printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
    92                     argv[1], argv[2], argv[3], rc);
     146                    t_argv[1], t_argv[2], t_argv[3], rc);
    93147                return CMD_FAILURE;
    94148        }
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    9795        if (NULL != rm->cwd)
    9896                free(rm->cwd);
    99 
    100         return;
    10197}
    10298
     
    131127                }
    132128        }
     129
     130        closedir(dirp);
    133131       
    134132        return ret;
  • uspace/app/bdsh/cmds/modules/sleep/sleep.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
  • uspace/app/bdsh/compl.h

    r2bdf8313 rb0f00a9  
    11/*
    2  * Copyright (c) 2009 Martin Decky
     2 * Copyright (c) 2008 Tim Post
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #include <test.h>
     29#ifndef COMPL_H
     30#define COMPL_H
    3031
    31 const char *test_mips2(void)
    32 {
    33         return NULL;
    34 }
     32#include <tinput.h>
     33
     34extern tinput_compl_ops_t compl_ops;
     35
     36#endif
  • uspace/app/bdsh/config.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129/* Various things that are used in many places including a few
    230 * tidbits left over from autoconf prior to the HelenOS port */
     
    1139#define EXIT_FAILURE 1
    1240#endif
    13 
    14 /* Work around for getenv() */
    15 #define PATH "/srv:/app"
    16 #define PATH_DELIM ":"
    1741
    1842/* Used in many places */
  • uspace/app/bdsh/errors.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    3836#include "errors.h"
    3937#include "errstr.h"
     38#include "scli.h"
    4039
    4140volatile int cli_errno = CL_EOK;
  • uspace/app/bdsh/errors.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef ERRORS_H
    230#define ERRORS_H
  • uspace/app/bdsh/errstr.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef ERRSTR_H
    230#define ERRSTR_H
  • uspace/app/bdsh/exec.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    4240#include <str_error.h>
    4341#include <errno.h>
     42#include <vfs/vfs.h>
    4443
    4544#include "config.h"
     
    5352static char *find_command(char *);
    5453static int try_access(const char *);
     54
     55const char *search_dir[] = { "/app", "/srv", NULL };
    5556
    5657/* work-around for access() */
     
    7172static char *find_command(char *cmd)
    7273{
    73         char *path_tok;
    74         char *path[PATH_MAX];
    75         int n = 0, i = 0;
    76         size_t x = str_size(cmd) + 2;
     74        size_t i;
    7775
    7876        found = (char *)malloc(PATH_MAX);
     
    8381        }
    8482
    85         path_tok = str_dup(PATH);
    86 
    87         /* Extract the PATH env to a path[] array */
    88         path[n] = strtok(path_tok, PATH_DELIM);
    89         while (NULL != path[n]) {
    90                 if ((str_size(path[n]) + x ) > PATH_MAX) {
    91                         cli_error(CL_ENOTSUP,
    92                                 "Segment %d of path is too large, search ends at segment %d",
    93                                 n, n-1);
    94                         break;
    95                 }
    96                 path[++n] = strtok(NULL, PATH_DELIM);
    97         }
    98 
    9983        /* We now have n places to look for the command */
    100         for (i=0; path[i]; i++) {
     84        for (i = 0; search_dir[i] != NULL; i++) {
    10185                memset(found, 0, sizeof(found));
    102                 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);
     86                snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd);
    10387                if (-1 != try_access(found)) {
    104                         free(path_tok);
    10588                        return (char *) found;
    10689                }
     
    10891
    10992        /* We didn't find it, just give it back as-is. */
    110         free(path_tok);
    11193        return (char *) cmd;
    11294}
    11395
    114 unsigned int try_exec(char *cmd, char **argv)
     96unsigned int try_exec(char *cmd, char **argv, iostate_t *io)
    11597{
    11698        task_id_t tid;
    11799        task_exit_t texit;
    118100        char *tmp;
    119         int rc, retval;
     101        int rc, retval, i;
     102        int file_handles[3];
     103        int *file_handles_p[4];
     104        FILE *files[3];
    120105
    121106        tmp = str_dup(find_command(cmd));
    122107        free(found);
     108       
     109        files[0] = io->stdin;
     110        files[1] = io->stdout;
     111        files[2] = io->stderr;
     112       
     113        for (i = 0; i < 3 && files[i] != NULL; i++) {
     114                if (fhandle(files[i], &file_handles[i]) == EOK) {
     115                        file_handles_p[i] = &file_handles[i];
     116                }
     117                else {
     118                        file_handles_p[i] = NULL;
     119                }
     120        }
     121        file_handles_p[i] = NULL;
    123122
    124         rc = task_spawnv(&tid, tmp, (const char **) argv);
     123        rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p);
    125124        free(tmp);
    126125
     
    135134                printf("%s: Failed waiting for command (%s)\n", progname,
    136135                    str_error(rc));
     136                return 1;
    137137        } else if (texit != TASK_EXIT_NORMAL) {
    138138                printf("%s: Command failed (unexpectedly terminated)\n", progname);
     139                return 1;
    139140        } else if (retval != 0) {
    140141                printf("%s: Command failed (exit code %d)\n",
    141142                    progname, retval);
     143                return 1;
    142144        }
    143145
  • uspace/app/bdsh/exec.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef EXEC_H
    230#define EXEC_H
    331
    432#include <task.h>
     33#include "scli.h"
    534
    6 extern unsigned int try_exec(char *, char **);
     35extern const char *search_dir[];
     36
     37extern unsigned int try_exec(char *, char **, iostate_t *);
    738
    839#endif
  • uspace/app/bdsh/input.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2011 Jiri Svoboda
     4 * Copyright (c) 2011 Martin Sucha
    25 * All rights reserved.
    36 *
    47 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     8 * modification, are permitted provided that the following conditions
     9 * are met:
    610 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     11 * - Redistributions of source code must retain the above copyright
     12 *   notice, this list of conditions and the following disclaimer.
     13 * - Redistributions in binary form must reproduce the above copyright
     14 *   notice, this list of conditions and the following disclaimer in the
     15 *   documentation and/or other materials provided with the distribution.
     16 * - The name of the author may not be used to endorse or promote products
     17 *   derived from this software without specific prior written permission.
    918 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2929 */
    3030
     
    4545
    4646#include "config.h"
     47#include "compl.h"
    4748#include "util.h"
    4849#include "scli.h"
     
    5051#include "errors.h"
    5152#include "exec.h"
     53#include "tok.h"
    5254
    5355extern volatile unsigned int cli_quit;
     
    5557/** Text input field. */
    5658static tinput_t *tinput;
     59
     60/* Private helpers */
     61static int run_command(char **, cliuser_t *, iostate_t *);
     62static void print_pipe_usage(void);
    5763
    5864/* Tokenizes input from console, sees if the first word is a built-in, if so
    5965 * invokes the built-in entry point (a[0]) passing all arguments in a[] to
    6066 * the handler */
    61 int tok_input(cliuser_t *usr)
    62 {
     67int process_input(cliuser_t *usr)
     68{
     69        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
     70        if (tokens == NULL)
     71                return ENOMEM;
     72       
    6373        char *cmd[WORD_MAX];
    64         int n = 0, i = 0;
    6574        int rc = 0;
    66         char *tmp;
    67 
    68         if (NULL == usr->line)
     75        tokenizer_t tok;
     76        unsigned int i, pipe_count, processed_pipes;
     77        unsigned int pipe_pos[2];
     78        char *redir_from = NULL;
     79        char *redir_to = NULL;
     80
     81        if (usr->line == NULL) {
     82                free(tokens);
    6983                return CL_EFAIL;
    70 
    71         tmp = str_dup(usr->line);
    72 
    73         cmd[n] = strtok(tmp, " ");
    74         while (cmd[n] && n < WORD_MAX) {
    75                 cmd[++n] = strtok(NULL, " ");
    76         }
    77 
    78         /* We have rubbish */
    79         if (NULL == cmd[0]) {
    80                 rc = CL_ENOENT;
    81                 goto finit;
    82         }
    83 
    84         /* Its a builtin command ? */
    85         if ((i = (is_builtin(cmd[0]))) > -1) {
    86                 rc = run_builtin(i, cmd, usr);
    87                 goto finit;
    88         /* Its a module ? */
    89         } else if ((i = (is_module(cmd[0]))) > -1) {
    90                 rc = run_module(i, cmd);
    91                 goto finit;
    92         }
    93 
    94         /* See what try_exec thinks of it */
    95         rc = try_exec(cmd[0], cmd);
    96 
     84        }
     85
     86        rc = tok_init(&tok, usr->line, tokens, WORD_MAX);
     87        if (rc != EOK) {
     88                goto finit;
     89        }
     90       
     91        size_t tokens_length;
     92        rc = tok_tokenize(&tok, &tokens_length);
     93        if (rc != EOK) {
     94                goto finit;
     95        }
     96       
     97        if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {
     98                tokens++;
     99                tokens_length--;
     100        }
     101       
     102        if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {
     103                tokens_length--;
     104        }
     105       
     106        /* Until full support for pipes is implemented, allow for a simple case:
     107         * [from <file> |] command [| to <file>]
     108         *
     109         * First find the pipes and check that there are no more
     110         */
     111        for (i = 0, pipe_count = 0; i < tokens_length; i++) {
     112                if (tokens[i].type == TOKTYPE_PIPE) {
     113                        if (pipe_count >= 2) {
     114                                print_pipe_usage();
     115                                rc = ENOTSUP;
     116                                goto finit;
     117                        }
     118                        pipe_pos[pipe_count] = i;
     119                        pipe_count++;
     120                }
     121        }
     122       
     123        unsigned int cmd_token_start = 0;
     124        unsigned int cmd_token_end = tokens_length;
     125       
     126        processed_pipes = 0;
     127       
     128        /* Check if the first part (from <file> |) is present */
     129        if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) {
     130                /* Ignore the first three tokens (from, file, pipe) and set from */
     131                redir_from = tokens[2].text;
     132                cmd_token_start = pipe_pos[0]+1;
     133                processed_pipes++;
     134        }
     135       
     136        /* Check if the second part (| to <file>) is present */
     137        if ((pipe_count - processed_pipes) > 0 &&
     138            (pipe_pos[processed_pipes] == tokens_length - 4 ||
     139            (pipe_pos[processed_pipes] == tokens_length - 5 &&
     140            tokens[tokens_length-4].type == TOKTYPE_SPACE )) &&
     141            str_cmp(tokens[tokens_length-3].text, "to") == 0) {
     142                /* Ignore the last three tokens (pipe, to, file) and set to */
     143                redir_to = tokens[tokens_length-1].text;
     144                cmd_token_end = pipe_pos[processed_pipes];
     145                processed_pipes++;
     146        }
     147       
     148        if (processed_pipes != pipe_count) {
     149                print_pipe_usage();
     150                rc = ENOTSUP;
     151                goto finit;
     152        }
     153       
     154        /* Convert tokens of the command to string array */
     155        unsigned int cmd_pos = 0;
     156        for (i = cmd_token_start; i < cmd_token_end; i++) {
     157                if (tokens[i].type != TOKTYPE_SPACE) {
     158                        cmd[cmd_pos++] = tokens[i].text;
     159                }
     160        }
     161        cmd[cmd_pos++] = NULL;
     162       
     163        if (cmd[0] == NULL) {
     164                print_pipe_usage();
     165                rc = ENOTSUP;
     166                goto finit;
     167        }
     168       
     169        iostate_t new_iostate = {
     170                .stdin = stdin,
     171                .stdout = stdout,
     172                .stderr = stderr
     173        };
     174       
     175        FILE *from = NULL;
     176        FILE *to = NULL;
     177       
     178        if (redir_from) {
     179                from = fopen(redir_from, "r");
     180                if (from == NULL) {
     181                        printf("Cannot open file %s\n", redir_from);
     182                        rc = errno;
     183                        goto finit_with_files;
     184                }
     185                new_iostate.stdin = from;
     186        }
     187       
     188       
     189        if (redir_to) {
     190                to = fopen(redir_to, "w");
     191                if (to == NULL) {
     192                        printf("Cannot open file %s\n", redir_to);
     193                        rc = errno;
     194                        goto finit_with_files;
     195                }
     196                new_iostate.stdout = to;
     197        }
     198
     199        rc = run_command(cmd, usr, &new_iostate);
     200       
     201finit_with_files:
     202        if (from != NULL) {
     203                fclose(from);
     204        }
     205        if (to != NULL) {
     206                fclose(to);
     207        }
     208       
    97209finit:
    98210        if (NULL != usr->line) {
     
    100212                usr->line = (char *) NULL;
    101213        }
    102         if (NULL != tmp)
    103                 free(tmp);
     214        tok_fini(&tok);
     215        free(tokens);
    104216
    105217        return rc;
     218}
     219
     220void print_pipe_usage()
     221{
     222        printf("Invalid syntax!\n");
     223        printf("Usage of redirection (pipes in the future):\n");
     224        printf("from filename | command ...\n");
     225        printf("from filename | command ... | to filename\n");
     226        printf("command ... | to filename\n");
     227       
     228}
     229
     230int run_command(char **cmd, cliuser_t *usr, iostate_t *new_iostate)
     231{
     232        int id = 0;
     233       
     234        /* We have rubbish */
     235        if (NULL == cmd[0]) {
     236                return CL_ENOENT;
     237        }
     238       
     239        /* Is it a builtin command ? */
     240        if ((id = (is_builtin(cmd[0]))) > -1) {
     241                return run_builtin(id, cmd, usr, new_iostate);
     242        }
     243       
     244        /* Is it a module ? */
     245        if ((id = (is_module(cmd[0]))) > -1) {
     246                return run_module(id, cmd, new_iostate);
     247        }
     248
     249        /* See what try_exec thinks of it */
     250        return try_exec(cmd[0], cmd, new_iostate);
    106251}
    107252
     
    110255        char *str;
    111256        int rc;
    112 
    113         fflush(stdout);
    114         console_set_style(fphone(stdout), STYLE_EMPHASIS);
    115         printf("%s", usr->prompt);
    116         fflush(stdout);
    117         console_set_style(fphone(stdout), STYLE_NORMAL);
     257       
     258        tinput_set_prompt(tinput, usr->prompt);
    118259
    119260        rc = tinput_read(tinput, &str);
     
    148289        }
    149290
     291        tinput_set_compl_ops(tinput, &compl_ops);
     292
    150293        return 0;
    151294}
  • uspace/app/bdsh/input.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef INPUT_H
    230#define INPUT_H
     
    735
    836extern void get_input(cliuser_t *);
    9 extern int tok_input(cliuser_t *);
     37extern int process_input(cliuser_t *);
    1038extern int input_init(void);
    1139
  • uspace/app/bdsh/scli.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1/*
     2 * Copyright (c) 2008 Tim Post
    23 * All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    68 *
    7  * Redistributions of source code must retain the above copyright notice, this
    8  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    916 *
    10  * Redistributions in binary form must reproduce the above copyright notice,
    11  * this list of conditions and the following disclaimer in the documentation
    12  * and/or other materials provided with the distribution.
    13  *
    14  * Neither the name of the original program's authors nor the names of its
    15  * contributors may be used to endorse or promote products derived from this
    16  * software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2927 */
    3028
     
    4240/* See scli.h */
    4341static cliuser_t usr;
     42static iostate_t *iostate;
     43static iostate_t stdiostate;
    4444
    4545/* Globals that are modified during start-up that modules/builtins
     
    8282}
    8383
     84iostate_t *get_iostate(void)
     85{
     86        return iostate;
     87}
     88
     89
     90void set_iostate(iostate_t *ios)
     91{
     92        iostate = ios;
     93        stdin = ios->stdin;
     94        stdout = ios->stdout;
     95        stderr = ios->stderr;
     96}
     97
    8498int main(int argc, char *argv[])
    8599{
    86100        int ret = 0;
     101       
     102        stdiostate.stdin = stdin;
     103        stdiostate.stdout = stdout;
     104        stdiostate.stderr = stderr;
     105        iostate = &stdiostate;
    87106
    88107        if (cli_init(&usr))
     
    92111                get_input(&usr);
    93112                if (NULL != usr.line) {
    94                         ret = tok_input(&usr);
     113                        ret = process_input(&usr);
    95114                        cli_set_prompt(&usr);
    96115                        usr.lasterr = ret;
  • uspace/app/bdsh/scli.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef SCLI_H
    230#define SCLI_H
     
    432#include "config.h"
    533#include <stdint.h>
     34#include <stdio.h>
    635
    736typedef struct {
     
    1342} cliuser_t;
    1443
     44typedef struct {
     45        FILE *stdin;
     46        FILE *stdout;
     47        FILE *stderr;
     48} iostate_t;
     49
    1550extern const char *progname;
    1651
     52extern iostate_t *get_iostate(void);
     53extern void set_iostate(iostate_t *);
     54
    1755#endif
  • uspace/app/bdsh/util.c

    r2bdf8313 rb0f00a9  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> - All rights reserved
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
    24 *
    35 * Redistribution and use in source and binary forms, with or without
    4  * modification, are permitted provided that the following conditions are met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
    58 *
    6  * Redistributions of source code must retain the above copyright notice, this
    7  * list of conditions and the following disclaimer.
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
    816 *
    9  * Redistributions in binary form must reproduce the above copyright notice,
    10  * this list of conditions and the following disclaimer in the documentation
    11  * and/or other materials provided with the distribution.
    12  *
    13  * Neither the name of the original program's authors nor the names of its
    14  * contributors may be used to endorse or promote products derived from this
    15  * software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    27  * POSSIBILITY OF SUCH DAMAGE.
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2827 */
    2928
     
    6968        return 0;
    7069}
    71 
    72 
  • uspace/app/bdsh/util.h

    r2bdf8313 rb0f00a9  
     1/*
     2 * Copyright (c) 2008 Tim Post
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#ifndef UTIL_H
    230#define UTIL_H
  • uspace/app/blkdump/Makefile

    r2bdf8313 rb0f00a9  
    2929
    3030USPACE_PREFIX = ../..
    31 EXTRA_CFLAGS = -Iinclude
    32 LIBRARY = libpacket
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
     33BINARY = blkdump
    3334
    3435SOURCES = \
    35         generic/packet_server.c
     36        blkdump.c
    3637
    3738include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/bnchmark/Makefile

    r2bdf8313 rb0f00a9  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
     2# Copyright (c) 2011 Martin Sucha
    43# All rights reserved.
    54#
     
    2827#
    2928
    30 USPACE_PREFIX = ../../../..
    31 BINARY = fhc
     29USPACE_PREFIX = ../..
     30BINARY = bnchmark
    3231
    3332SOURCES = \
    34         fhc.c
     33        bnchmark.c
    3534
    3635include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/edit/edit.c

    r2bdf8313 rb0f00a9  
    9494} doc_t;
    9595
    96 static int con;
     96static console_ctrl_t *con;
    9797static doc_t doc;
    9898static bool done;
     
    115115static void cursor_setvis(bool visible);
    116116
    117 static void key_handle_unmod(console_event_t const *ev);
    118 static void key_handle_ctrl(console_event_t const *ev);
    119 static void key_handle_shift(console_event_t const *ev);
     117static void key_handle_unmod(kbd_event_t const *ev);
     118static void key_handle_ctrl(kbd_event_t const *ev);
     119static void key_handle_shift(kbd_event_t const *ev);
    120120static void key_handle_movement(unsigned int key, bool shift);
    121121
     
    158158int main(int argc, char *argv[])
    159159{
    160         console_event_t ev;
     160        kbd_event_t ev;
    161161        coord_t coord;
    162162        bool new_file;
     
    164164        spt_t pt;
    165165
    166         con = fphone(stdout);
     166        con = console_init(stdin, stdout);
    167167        console_clear(con);
    168168
     
    219219
    220220        while (!done) {
    221                 console_get_event(con, &ev);
     221                console_get_kbd_event(con, &ev);
    222222                pane.rflags = 0;
    223223
     
    277277
    278278/** Handle key without modifier. */
    279 static void key_handle_unmod(console_event_t const *ev)
     279static void key_handle_unmod(kbd_event_t const *ev)
    280280{
    281281        switch (ev->key) {
     
    320320
    321321/** Handle Shift-key combination. */
    322 static void key_handle_shift(console_event_t const *ev)
     322static void key_handle_shift(kbd_event_t const *ev)
    323323{
    324324        switch (ev->key) {
     
    344344
    345345/** Handle Ctrl-key combination. */
    346 static void key_handle_ctrl(console_event_t const *ev)
     346static void key_handle_ctrl(kbd_event_t const *ev)
    347347{
    348348        switch (ev->key) {
     
    497497static char *filename_prompt(char const *prompt, char const *init_value)
    498498{
    499         console_event_t ev;
     499        kbd_event_t ev;
    500500        char *str;
    501501        wchar_t buffer[INFNAME_MAX_LEN + 1];
     
    517517
    518518        while (!done) {
    519                 console_get_event(con, &ev);
     519                console_get_kbd_event(con, &ev);
    520520
    521521                if (ev.type == KEY_PRESS) {
     
    531531                                        if (nc > 0) {
    532532                                                putchar('\b');
    533                                                 fflush(stdout);
     533                                                console_flush(con);
    534534                                                --nc;
    535535                                        }
     
    541541                                        if (ev.c >= 32 && nc < max_len) {
    542542                                                putchar(ev.c);
    543                                                 fflush(stdout);
     543                                                console_flush(con);
    544544                                                buffer[nc++] = ev.c;
    545545                                        }
     
    689689                for (j = 0; j < scr_columns; ++j)
    690690                        putchar(' ');
    691                 fflush(stdout);
     691                console_flush(con);
    692692        }
    693693
     
    757757                if (coord_cmp(&csel_start, &rbc) <= 0 &&
    758758                    coord_cmp(&rbc, &csel_end) < 0) {
    759                         fflush(stdout);
     759                        console_flush(con);
    760760                        console_set_style(con, STYLE_SELECTED);
    761                         fflush(stdout);
     761                        console_flush(con);
    762762                }
    763763
     
    768768                while (pos < size) {
    769769                        if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
    770                                 fflush(stdout);
     770                                console_flush(con);
    771771                                console_set_style(con, STYLE_SELECTED);
    772                                 fflush(stdout);
     772                                console_flush(con);
    773773                        }
    774774       
    775775                        if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    776                                 fflush(stdout);
     776                                console_flush(con);
    777777                                console_set_style(con, STYLE_NORMAL);
    778                                 fflush(stdout);
     778                                console_flush(con);
    779779                        }
    780780       
     
    794794
    795795                if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    796                         fflush(stdout);
     796                        console_flush(con);
    797797                        console_set_style(con, STYLE_NORMAL);
    798                         fflush(stdout);
     798                        console_flush(con);
    799799                }
    800800
     
    808808                for (j = 0; j < fill; ++j)
    809809                        putchar(' ');
    810                 fflush(stdout);
     810                console_flush(con);
    811811                console_set_style(con, STYLE_NORMAL);
    812812        }
     
    833833        int pos = scr_columns - 1 - n;
    834834        printf("%*s", pos, "");
    835         fflush(stdout);
     835        console_flush(con);
    836836        console_set_style(con, STYLE_NORMAL);
    837837
     
    11581158        int pos = -(scr_columns - 3);
    11591159        printf(" %*s ", pos, str);
    1160         fflush(stdout);
     1160        console_flush(con);
    11611161        console_set_style(con, STYLE_NORMAL);
    11621162
  • uspace/app/edit/sheet.c

    r2bdf8313 rb0f00a9  
    7575                return ENOMEM;
    7676
    77         list_initialize(&sh->tags_head);
     77        list_initialize(&sh->tags);
    7878
    7979        return EOK;
     
    9797        char *ipp;
    9898        size_t sz;
    99         link_t *link;
    10099        tag_t *tag;
    101100        char *newp;
     
    121120        /* Adjust tags. */
    122121
    123         link = sh->tags_head.next;
    124         while (link != &sh->tags_head) {
     122        list_foreach(sh->tags, link) {
    125123                tag = list_get_instance(link, tag_t, link);
    126124
     
    129127                else if (tag->b_off == pos->b_off && dir == dir_before)
    130128                        tag->b_off += sz;
    131 
    132                 link = link->next;
    133129        }
    134130
     
    150146        char *spp;
    151147        size_t sz;
    152         link_t *link;
    153148        tag_t *tag;
    154149        char *newp;
     
    162157
    163158        /* Adjust tags. */
    164         link = sh->tags_head.next;
    165         while (link != &sh->tags_head) {
     159        list_foreach(sh->tags, link) {
    166160                tag = list_get_instance(link, tag_t, link);
    167161
     
    170164                else if (tag->b_off >= spos->b_off)
    171165                        tag->b_off = spos->b_off;
    172 
    173                 link = link->next;
    174166        }
    175167
     
    328320        tag->b_off = pt->b_off;
    329321        tag->sh = sh;
    330         list_append(&tag->link, &sh->tags_head);
     322        list_append(&tag->link, &sh->tags);
    331323}
    332324
  • uspace/app/edit/sheet.h

    r2bdf8313 rb0f00a9  
    5757        char *data;
    5858
    59         link_t tags_head;
     59        list_t tags;
    6060} sheet_t;
    6161
     
    9191        /* Note: This structure is opaque for the user. */
    9292
    93         /** Link to list of all tags in the sheet (see sheet_t.tags_head) */
     93        /** Link to list of all tags in the sheet (see sheet_t.tags) */
    9494        link_t link;
    9595        sheet_t *sh;
  • uspace/app/getterm/version.c

    r2bdf8313 rb0f00a9  
    6161        printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp);
    6262        printf("Running on %s (%s)\n", arch, term);
    63         printf("Copyright (c) 2001-2010 HelenOS project\n\n");
     63        printf("Copyright (c) 2001-2011 HelenOS project\n\n");
    6464}
    6565
  • uspace/app/init/init.c

    r2bdf8313 rb0f00a9  
    4646#include <macros.h>
    4747#include <str.h>
    48 #include <devmap.h>
     48#include <loc.h>
    4949#include <str_error.h>
    5050#include "init.h"
     
    5353#define ROOT_MOUNT_POINT  "/"
    5454
    55 #define DEVFS_FS_TYPE      "devfs"
    56 #define DEVFS_MOUNT_POINT  "/dev"
     55#define LOCFS_FS_TYPE      "locfs"
     56#define LOCFS_MOUNT_POINT  "/loc"
    5757
    5858#define TMPFS_FS_TYPE      "tmpfs"
     
    6666#define APP_GETTERM  "/app/getterm"
    6767
     68/** Print banner */
    6869static void info_print(void)
    6970{
     
    7172}
    7273
     74/** Report mount operation success */
    7375static bool mount_report(const char *desc, const char *mntpt,
    7476    const char *fstype, const char *dev, int rc)
     
    100102}
    101103
     104/** Mount root filesystem
     105 *
     106 * The operation blocks until the root filesystem
     107 * server is ready for mounting.
     108 *
     109 * @param[in] fstype Root filesystem type.
     110 *
     111 * @return True on success.
     112 * @return False on failure.
     113 *
     114 */
    102115static bool mount_root(const char *fstype)
    103116{
     
    108121       
    109122        int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
    110             IPC_FLAG_BLOCKING);
     123            IPC_FLAG_BLOCKING, 0);
    111124        return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
    112125            ROOT_DEVICE, rc);
    113126}
    114127
    115 static bool mount_devfs(void)
    116 {
    117         int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
    118             IPC_FLAG_BLOCKING);
    119         return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
    120             NULL, rc);
     128/** Mount locfs filesystem
     129 *
     130 * The operation blocks until the locfs filesystem
     131 * server is ready for mounting.
     132 *
     133 * @return True on success.
     134 * @return False on failure.
     135 *
     136 */
     137static bool mount_locfs(void)
     138{
     139        int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
     140            IPC_FLAG_BLOCKING, 0);
     141        return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
     142            LOCFS_FS_TYPE, NULL, rc);
    121143}
    122144
     
    157179        rc = task_wait(id, &texit, &retval);
    158180        if (rc != EOK) {
    159                 printf("%s: Error waiting for %s (%s(\n", NAME, fname,
     181                printf("%s: Error waiting for %s (%s)\n", NAME, fname,
    160182                    str_error(rc));
    161183                return;
     
    174196}
    175197
    176 static void console(const char *dev)
    177 {
    178         char hid_in[DEVMAP_NAME_MAXLEN];
     198static void console(const char *isvc, const char *fbsvc)
     199{
     200        printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
     201       
     202        /* Wait for the input service to be ready */
     203        service_id_t service_id;
     204        int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
     205        if (rc != EOK) {
     206                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
     207                    str_error(rc));
     208                return;
     209        }
     210       
     211        /* Wait for the framebuffer service to be ready */
     212        rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING);
     213        if (rc != EOK) {
     214                printf("%s: Error waiting on %s (%s)\n", NAME, fbsvc,
     215                    str_error(rc));
     216                return;
     217        }
     218       
     219        rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, isvc, fbsvc, NULL);
     220        if (rc != EOK) {
     221                printf("%s: Error spawning %s %s %s (%s)\n", NAME, SRV_CONSOLE,
     222                    isvc, fbsvc, str_error(rc));
     223        }
     224}
     225
     226static void getterm(const char *svc, const char *app, bool wmsg)
     227{
     228        char term[LOC_NAME_MAXLEN];
    179229        int rc;
    180230       
    181         snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
    182        
    183         printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
    184        
    185         /* Wait for the input device to be ready */
    186         devmap_handle_t handle;
    187         rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    188         if (rc != EOK) {
    189                 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
    190                     str_error(rc));
    191                 return;
    192         }
    193        
    194         rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);
    195         if (rc != EOK) {
    196                 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
    197                     hid_in, str_error(rc));
    198         }
    199 }
    200 
    201 static void getterm(const char *dev, const char *app, bool wmsg)
    202 {
    203         char term[DEVMAP_NAME_MAXLEN];
    204         int rc;
    205        
    206         snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
     231        snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
    207232       
    208233        printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
    209234       
    210         /* Wait for the terminal device to be ready */
    211         devmap_handle_t handle;
    212         rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
     235        /* Wait for the terminal service to be ready */
     236        service_id_t service_id;
     237        rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
    213238        if (rc != EOK) {
    214239                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     
    236261static bool mount_tmpfs(void)
    237262{
    238         int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0);
     263        int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
    239264        return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
    240265            TMPFS_FS_TYPE, NULL, rc);
     
    243268static bool mount_data(void)
    244269{
    245         int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
     270        int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0, 0);
    246271        return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
    247272            DATA_DEVICE, rc);
     
    262287        }
    263288       
    264         spawn("/srv/devfs");
     289        spawn("/srv/locfs");
    265290        spawn("/srv/taskmon");
    266291       
    267         if (!mount_devfs()) {
     292        if (!mount_locfs()) {
    268293                printf("%s: Exiting\n", NAME);
    269294                return -2;
     
    272297        mount_tmpfs();
    273298       
    274 #ifdef CONFIG_START_DEVMAN
    275299        spawn("/srv/devman");
    276 #endif
    277300        spawn("/srv/apic");
    278301        spawn("/srv/i8259");
    279         spawn("/srv/fhc");
    280302        spawn("/srv/obio");
    281303        srv_start("/srv/cuda_adb");
    282304        srv_start("/srv/i8042");
    283305        srv_start("/srv/s3c24ser");
    284         srv_start("/srv/adb_ms");
    285         srv_start("/srv/char_ms");
    286306        srv_start("/srv/s3c24ts");
    287307       
     308        spawn("/srv/net");
     309       
    288310        spawn("/srv/fb");
    289         spawn("/srv/kbd");
    290         console("hid_in/kbd");
     311        spawn("/srv/input");
     312        console("hid/input", "hid/fb0");
    291313       
    292314        spawn("/srv/clip");
     
    304326       
    305327#ifdef CONFIG_MOUNT_DATA
     328        /* Make sure fat is running. */
     329        if (str_cmp(STRING(RDFMT), "fat") != 0) {
     330                srv_start("/srv/fat");
     331        }
    306332        mount_data();
    307333#else
  • uspace/app/klog/klog.c

    r2bdf8313 rb0f00a9  
    143143 * Receives kernel klog notifications.
    144144 *
    145  * @param callid IPC call ID.
    146  * @param call   IPC call structure.
     145 * @param callid IPC call ID
     146 * @param call   IPC call structure
     147 * @param arg    Local argument
    147148 *
    148149 */
  • uspace/app/locinfo/Makefile

    r2bdf8313 rb0f00a9  
    11#
    2 # Copyright (c) 2010 Jiri Svoboda
     2# Copyright (c) 2011 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 USPACE_PREFIX = ../../..
     29USPACE_PREFIX = ../..
    3030EXTRA_CFLAGS = -Iinclude
    31 BINARY = adb_ms
     31BINARY = locinfo
    3232
    3333SOURCES = \
    34         adb_mouse.c \
    35         adb_dev.c
     34        locinfo.c
    3635
    3736include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/locinfo/locinfo.c

    r2bdf8313 rb0f00a9  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup tester
    30  * @brief Test devman service.
     29/** @addtogroup locinfo
    3130 * @{
    3231 */
    33 /**
    34  * @file
     32/** @file locinfo.c Print information from location service.
    3533 */
    3634
    37 #include <inttypes.h>
    3835#include <errno.h>
    39 #include <str_error.h>
     36#include <loc.h>
     37#include <stdio.h>
     38#include <stdlib.h>
     39#include <str.h>
    4040#include <sys/types.h>
    41 #include <async.h>
    42 #include <devman.h>
    43 #include <str.h>
    44 #include <vfs/vfs.h>
    45 #include <sys/stat.h>
    46 #include <fcntl.h>
    47 #include "../tester.h"
     41#include <sys/typefmt.h>
    4842
    49 #define DEVICE_PATH_NORMAL "/virt/null/a"
    50 #define DEVICE_CLASS "virt-null"
    51 #define DEVICE_CLASS_NAME "1"
    52 #define DEVICE_PATH_CLASSES DEVICE_CLASS "/" DEVICE_CLASS_NAME
     43#define NAME "locinfo"
    5344
    54 const char *test_devman1(void)
     45int main(int argc, char *argv[])
    5546{
    56         devman_handle_t handle_primary;
    57         devman_handle_t handle_class;
    58        
     47        category_id_t *cat_ids;
     48        size_t cat_cnt;
     49        service_id_t *svc_ids;
     50        size_t svc_cnt;
     51
     52        size_t i, j;
     53        char *cat_name;
     54        char *svc_name;
    5955        int rc;
    60        
    61         TPRINTF("Asking for handle of `%s'...\n", DEVICE_PATH_NORMAL);
    62         rc = devman_device_get_handle(DEVICE_PATH_NORMAL, &handle_primary, 0);
     56
     57        rc = loc_get_categories(&cat_ids, &cat_cnt);
    6358        if (rc != EOK) {
    64                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    65                 if (rc == ENOENT) {
    66                         TPRINTF("Have you compiled the test drivers?\n");
    67                 }
    68                 return "Failed getting device handle";
     59                printf(NAME ": Error getting list of categories.\n");
     60                return 1;
    6961        }
    7062
    71         TPRINTF("Asking for handle of `%s' by class..\n", DEVICE_PATH_CLASSES);
    72         rc = devman_device_get_handle_by_class(DEVICE_CLASS, DEVICE_CLASS_NAME,
    73             &handle_class, 0);
    74         if (rc != EOK) {
    75                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    76                 return "Failed getting device class handle";
     63        for (i = 0; i < cat_cnt; i++) {
     64                rc = loc_category_get_name(cat_ids[i], &cat_name);
     65                if (rc != EOK)
     66                        cat_name = str_dup("<unknown>");
     67
     68                if (cat_name == NULL) {
     69                        printf(NAME ": Error allocating memory.\n");
     70                        return 1;
     71                }
     72
     73                printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]);
     74
     75                rc = loc_category_get_svcs(cat_ids[i], &svc_ids, &svc_cnt);
     76                if (rc != EOK) {
     77                        printf(NAME ": Failed getting list of services in "
     78                            "category %s, skipping.\n", cat_name);
     79                        free(cat_name);
     80                        continue;
     81                }
     82
     83                for (j = 0; j < svc_cnt; j++) {
     84                        rc = loc_service_get_name(svc_ids[j], &svc_name);
     85                        if (rc != EOK) {
     86                                printf(NAME ": Unknown service name (SID %"
     87                                    PRIun ").\n", svc_ids[j]);
     88                                continue;
     89                        }
     90                        printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]);
     91                }
     92
     93                free(svc_ids);
     94                free(cat_name);
    7795        }
    7896
    79         TPRINTF("Received handles %" PRIun " and %" PRIun ".\n",
    80             handle_primary, handle_class);
    81         if (handle_primary != handle_class) {
    82                 return "Retrieved different handles for the same device";
    83         }
    84 
    85         return NULL;
     97        free(cat_ids);
     98        return 0;
    8699}
    87100
  • uspace/app/mkfat/fat.h

    r2bdf8313 rb0f00a9  
    3838#define BS_BLOCK                0
    3939#define BS_SIZE                 512
     40#define DIRENT_SIZE             32
    4041
    41 #define DIRENT_SIZE             32
     42#define FAT12_CLST_MAX    4085
     43#define FAT16_CLST_MAX    65525
     44
     45#define FAT12   12
     46#define FAT16   16
     47#define FAT32   32
     48
     49#define FAT_CLUSTER_DOUBLE_SIZE(a) ((a) / 4)
    4250
    4351typedef struct fat_bs {
  • uspace/app/mkfat/mkfat.c

    r2bdf8313 rb0f00a9  
    3535 * @brief       Tool for creating new FAT file systems.
    3636 *
    37  * Currently we can only create 16-bit FAT.
     37 * Currently we can create 12/16/32-bit FAT.
    3838 */
    3939
     
    4242#include <libblock.h>
    4343#include <mem.h>
    44 #include <devmap.h>
     44#include <loc.h>
    4545#include <byteorder.h>
    4646#include <sys/types.h>
     
    5555#define div_round_up(a, b) (((a) + (b) - 1) / (b))
    5656
    57 /** Predefined file-system parameters */
     57/** Default file-system parameters */
    5858enum {
    59         sector_size             = 512,
    60         sectors_per_cluster     = 8,
    61         fat_count               = 2,
    62         reserved_clusters       = 2,
    63         media_descriptor        = 0xF8 /**< fixed disk */
     59        default_sector_size             = 512,
     60        default_sectors_per_cluster     = 4,
     61        default_fat_count               = 2,
     62        default_reserved_clusters       = 2,
     63        default_media_descriptor        = 0xF8 /**< fixed disk */
    6464};
    6565
    6666/** Configurable file-system parameters */
    6767typedef struct fat_cfg {
     68        int fat_type; /* FAT12 = 12, FAT16 = 16, FAT32 = 32 */
     69        size_t sector_size;
    6870        uint32_t total_sectors;
    6971        uint16_t root_ent_max;
    70         uint16_t addt_res_sectors;
     72        uint32_t addt_res_sectors;
     73        uint8_t sectors_per_cluster;
     74
     75        uint16_t reserved_sectors;
     76        uint32_t rootdir_sectors;
     77        uint32_t fat_sectors;
     78        uint32_t total_clusters;
     79        uint8_t fat_count;
    7180} fat_cfg_t;
    7281
    73 /** Derived file-system parameters */
    74 typedef struct fat_params {
    75         struct fat_cfg cfg;
    76         uint16_t reserved_sectors;
    77         uint16_t rootdir_sectors;
    78         uint32_t fat_sectors;
    79         uint16_t total_clusters;
    80 } fat_params_t;
    81 
    8282static void syntax_print(void);
    8383
    84 static int fat_params_compute(struct fat_cfg const *cfg,
    85     struct fat_params *par);
    86 static int fat_blocks_write(struct fat_params const *par,
    87     devmap_handle_t handle);
    88 static void fat_bootsec_create(struct fat_params const *par, struct fat_bs *bs);
     84static int fat_params_compute(struct fat_cfg *cfg);
     85static int fat_blocks_write(struct fat_cfg const *cfg, service_id_t service_id);
     86static void fat_bootsec_create(struct fat_cfg const *cfg, struct fat_bs *bs);
    8987
    9088int main(int argc, char **argv)
    9189{
    92         struct fat_params par;
    9390        struct fat_cfg cfg;
    9491
    9592        int rc;
    9693        char *dev_path;
    97         devmap_handle_t handle;
    98         size_t block_size;
     94        service_id_t service_id;
    9995        char *endptr;
    10096        aoff64_t dev_nblocks;
    10197
     98        cfg.sector_size = default_sector_size;
     99        cfg.sectors_per_cluster = default_sectors_per_cluster;
     100        cfg.fat_count = default_fat_count;
    102101        cfg.total_sectors = 0;
    103102        cfg.addt_res_sectors = 0;
    104103        cfg.root_ent_max = 128;
     104        cfg.fat_type = FAT16;
    105105
    106106        if (argc < 2) {
     
    111111
    112112        --argc; ++argv;
    113 
    114113        if (str_cmp(*argv, "--size") == 0) {
    115114                --argc; ++argv;
     
    130129        }
    131130
     131        if (str_cmp(*argv, "--type") == 0) {
     132                --argc; ++argv;
     133                if (*argv == NULL) {
     134                        printf(NAME ": Error, argument missing.\n");
     135                        syntax_print();
     136                        return 1;
     137                }
     138
     139                cfg.fat_type = strtol(*argv, &endptr, 10);
     140                if (*endptr != '\0') {
     141                        printf(NAME ": Error, invalid argument.\n");
     142                        syntax_print();
     143                        return 1;
     144                }
     145
     146                --argc; ++argv;
     147        }
     148
    132149        if (argc != 1) {
    133150                printf(NAME ": Error, unexpected argument.\n");
     
    137154
    138155        dev_path = *argv;
    139 
    140         rc = devmap_device_get_handle(dev_path, &handle, 0);
     156        printf("Device: %s\n", dev_path);
     157
     158        rc = loc_service_get_id(dev_path, &service_id, 0);
    141159        if (rc != EOK) {
    142160                printf(NAME ": Error resolving device `%s'.\n", dev_path);
     
    144162        }
    145163
    146         rc = block_init(handle, 2048);
     164        rc = block_init(EXCHANGE_SERIALIZE, service_id, 2048);
    147165        if (rc != EOK)  {
    148166                printf(NAME ": Error initializing libblock.\n");
     
    150168        }
    151169
    152         rc = block_get_bsize(handle, &block_size);
     170        rc = block_get_bsize(service_id, &cfg.sector_size);
    153171        if (rc != EOK) {
    154172                printf(NAME ": Error determining device block size.\n");
     
    156174        }
    157175
    158         rc = block_get_nblocks(handle, &dev_nblocks);
     176        rc = block_get_nblocks(service_id, &dev_nblocks);
    159177        if (rc != EOK) {
    160178                printf(NAME ": Warning, failed to obtain block device size.\n");
     
    162180                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
    163181                    dev_nblocks);
    164                 cfg.total_sectors = dev_nblocks;
    165         }
    166 
    167         if (block_size != 512) {
    168                 printf(NAME ": Error. Device block size is not 512 bytes.\n");
    169                 return 2;
     182                if (!cfg.total_sectors || dev_nblocks < cfg.total_sectors)
     183                        cfg.total_sectors = dev_nblocks;
    170184        }
    171185
     
    175189        }
    176190
    177         printf(NAME ": Creating FAT filesystem on device %s.\n", dev_path);
    178 
    179         rc = fat_params_compute(&cfg, &par);
     191        if (cfg.fat_type != FAT12 && cfg.fat_type != FAT16 && cfg.fat_type != FAT32) {
     192                printf(NAME ": Error. Unknown FAT type.\n");
     193                return 2;
     194        }
     195
     196        printf(NAME ": Creating FAT%d filesystem on device %s.\n", cfg.fat_type, dev_path);
     197
     198        rc = fat_params_compute(&cfg);
    180199        if (rc != EOK) {
    181200                printf(NAME ": Invalid file-system parameters.\n");
     
    183202        }
    184203
    185         rc = fat_blocks_write(&par, handle);
     204        rc = fat_blocks_write(&cfg, service_id);
    186205        if (rc != EOK) {
    187206                printf(NAME ": Error writing device.\n");
     
    189208        }
    190209
    191         block_fini(handle);
     210        block_fini(service_id);
    192211        printf("Success.\n");
    193212
     
    197216static void syntax_print(void)
    198217{
    199         printf("syntax: mkfat [--size <num_blocks>] <device_name>\n");
     218        printf("syntax: mkfat [--size <sectors>] [--type 12|16|32] <device_name>\n");
    200219}
    201220
     
    205224 * file system params.
    206225 */
    207 static int fat_params_compute(struct fat_cfg const *cfg, struct fat_params *par)
     226static int fat_params_compute(struct fat_cfg *cfg)
    208227{
    209228        uint32_t fat_bytes;
     
    211230
    212231        /*
    213          * Make a conservative guess on the FAT size needed for the file
    214          * system. The optimum could be potentially smaller since we
    215          * do not subtract size of the FAT itself when computing the
    216          * size of the data region.
    217          */
    218 
    219         par->reserved_sectors = 1 + cfg->addt_res_sectors;
    220         par->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE,
    221             sector_size);
    222         non_data_sectors_lb = par->reserved_sectors + par->rootdir_sectors;
    223 
    224         par->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb,
    225             sectors_per_cluster);
    226 
    227         fat_bytes = (par->total_clusters + 2) * 2;
    228         par->fat_sectors = div_round_up(fat_bytes, sector_size);
    229 
    230         par->cfg = *cfg;
     232         * Make a conservative guess on the FAT size needed for the file
     233         * system. The optimum could be potentially smaller since we
     234         * do not subtract size of the FAT itself when computing the
     235         * size of the data region.
     236         */
     237
     238        cfg->reserved_sectors = 1 + cfg->addt_res_sectors;
     239        if (cfg->fat_type != FAT32) {
     240                cfg->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE,
     241                        cfg->sector_size);
     242        } else
     243                cfg->rootdir_sectors = 0;
     244        non_data_sectors_lb = cfg->reserved_sectors + cfg->rootdir_sectors;
     245
     246        cfg->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb,
     247            cfg->sectors_per_cluster);
     248
     249        if ((cfg->fat_type == FAT12 && cfg->total_clusters > FAT12_CLST_MAX) ||
     250            (cfg->fat_type == FAT16 && (cfg->total_clusters <= FAT12_CLST_MAX ||
     251            cfg->total_clusters > FAT16_CLST_MAX)) ||
     252            (cfg->fat_type == FAT32 && cfg->total_clusters <= FAT16_CLST_MAX))
     253                return ENOSPC;
     254
     255        fat_bytes = div_round_up((cfg->total_clusters + 2) *
     256            FAT_CLUSTER_DOUBLE_SIZE(cfg->fat_type), 2);
     257        cfg->fat_sectors = div_round_up(fat_bytes, cfg->sector_size);
    231258
    232259        return EOK;
     
    234261
    235262/** Create file system with the given parameters. */
    236 static int fat_blocks_write(struct fat_params const *par, devmap_handle_t handle)
     263static int fat_blocks_write(struct fat_cfg const *cfg, service_id_t service_id)
    237264{
    238265        aoff64_t addr;
     
    243270        struct fat_bs bs;
    244271
    245         fat_bootsec_create(par, &bs);
    246 
    247         rc = block_write_direct(handle, BS_BLOCK, 1, &bs);
     272        fat_bootsec_create(cfg, &bs);
     273
     274        rc = block_write_direct(service_id, BS_BLOCK, 1, &bs);
    248275        if (rc != EOK)
    249276                return EIO;
     
    251278        addr = BS_BLOCK + 1;
    252279
    253         buffer = calloc(sector_size, 1);
     280        buffer = calloc(cfg->sector_size, 1);
    254281        if (buffer == NULL)
    255282                return ENOMEM;
     283        memset(buffer, 0, cfg->sector_size);
    256284
    257285        /* Reserved sectors */
    258         for (i = 0; i < par->reserved_sectors - 1; ++i) {
    259                 rc = block_write_direct(handle, addr, 1, buffer);
     286        for (i = 0; i < cfg->reserved_sectors - 1; ++i) {
     287                rc = block_write_direct(service_id, addr, 1, buffer);
    260288                if (rc != EOK)
    261289                        return EIO;
     
    265293
    266294        /* File allocation tables */
    267         for (i = 0; i < fat_count; ++i) {
     295        for (i = 0; i < cfg->fat_count; ++i) {
    268296                printf("Writing allocation table %d.\n", i + 1);
    269297
    270                 for (j = 0; j < par->fat_sectors; ++j) {
    271                         memset(buffer, 0, sector_size);
     298                for (j = 0; j < cfg->fat_sectors; ++j) {
     299                        memset(buffer, 0, cfg->sector_size);
    272300                        if (j == 0) {
    273                                 buffer[0] = media_descriptor;
     301                                buffer[0] = default_media_descriptor;
    274302                                buffer[1] = 0xFF;
    275303                                buffer[2] = 0xFF;
    276                                 buffer[3] = 0xFF;
     304                                if (cfg->fat_type == FAT16) {
     305                                        buffer[3] = 0xFF;
     306                                } else if (cfg->fat_type == FAT32) {
     307                                        buffer[3] = 0x0F;
     308                                        buffer[4] = 0xFF;
     309                                        buffer[5] = 0xFF;
     310                                        buffer[6] = 0xFF;
     311                                        buffer[7] = 0x0F;
     312                                        buffer[8] = 0xF8;
     313                                        buffer[9] = 0xFF;
     314                                        buffer[10] = 0xFF;
     315                                        buffer[11] = 0x0F;
     316                                }
    277317                        }
    278318
    279                         rc = block_write_direct(handle, addr, 1, buffer);
     319                        rc = block_write_direct(service_id, addr, 1, buffer);
    280320                        if (rc != EOK)
    281321                                return EIO;
     
    285325        }
    286326
     327        /* Root directory */
    287328        printf("Writing root directory.\n");
    288 
    289         memset(buffer, 0, sector_size);
    290 
    291         /* Root directory */
    292         for (i = 0; i < par->rootdir_sectors; ++i) {
    293                 rc = block_write_direct(handle, addr, 1, buffer);
    294                 if (rc != EOK)
    295                         return EIO;
    296 
    297                 ++addr;
     329        memset(buffer, 0, cfg->sector_size);
     330        if (cfg->fat_type != FAT32) {
     331                size_t idx;
     332                for (idx = 0; idx < cfg->rootdir_sectors; ++idx) {
     333                        rc = block_write_direct(service_id, addr, 1, buffer);
     334                        if (rc != EOK)
     335                                return EIO;
     336
     337                        ++addr;
     338                }
     339        } else {
     340                for (i = 0; i < cfg->sectors_per_cluster; i++) {
     341                        rc = block_write_direct(service_id, addr, 1, buffer);
     342                        if (rc != EOK)
     343                                return EIO;
     344
     345                        ++addr;
     346                }       
    298347        }
    299348
     
    304353
    305354/** Construct boot sector with the given parameters. */
    306 static void fat_bootsec_create(struct fat_params const *par, struct fat_bs *bs)
     355static void fat_bootsec_create(struct fat_cfg const *cfg, struct fat_bs *bs)
    307356{
    308357        memset(bs, 0, sizeof(*bs));
     
    315364
    316365        /* BIOS Parameter Block */
    317         bs->bps = host2uint16_t_le(sector_size);
    318         bs->spc = sectors_per_cluster;
    319         bs->rscnt = host2uint16_t_le(par->reserved_sectors);
    320         bs->fatcnt = fat_count;
    321         bs->root_ent_max = host2uint16_t_le(par->cfg.root_ent_max);
    322 
    323         if (par->cfg.total_sectors < 0x10000)
    324                 bs->totsec16 = host2uint16_t_le(par->cfg.total_sectors);
    325         else
    326                 bs->totsec16 = host2uint16_t_le(0);
    327 
    328         bs->mdesc = media_descriptor;
    329         bs->sec_per_fat = host2uint16_t_le(par->fat_sectors);
     366        bs->bps = host2uint16_t_le(cfg->sector_size);
     367        bs->spc = cfg->sectors_per_cluster;
     368        bs->rscnt = host2uint16_t_le(cfg->reserved_sectors);
     369        bs->fatcnt = cfg->fat_count;
     370        bs->root_ent_max = host2uint16_t_le(cfg->root_ent_max);
     371
     372        if (cfg->total_sectors < 0x10000) {
     373                bs->totsec16 = host2uint16_t_le(cfg->total_sectors);
     374                bs->totsec32 = 0;
     375        } else {
     376                bs->totsec16 = 0;
     377                bs->totsec32 = host2uint32_t_le(cfg->total_sectors);
     378        }
     379
     380        bs->mdesc = default_media_descriptor;
    330381        bs->sec_per_track = host2uint16_t_le(63);
     382        bs->signature = host2uint16_t_be(0x55AA);
    331383        bs->headcnt = host2uint16_t_le(6);
    332384        bs->hidden_sec = host2uint32_t_le(0);
    333385
    334         if (par->cfg.total_sectors >= 0x10000)
    335                 bs->totsec32 = host2uint32_t_le(par->cfg.total_sectors);
    336         else
    337                 bs->totsec32 = host2uint32_t_le(0);
    338 
    339         /* Extended BPB */
    340         bs->pdn = 0x80;
    341         bs->ebs = 0x29;
    342         bs->id = host2uint32_t_be(0x12345678);
    343 
    344         memcpy(bs->label, "HELENOS_NEW", 11);
    345         memcpy(bs->type, "FAT16   ", 8);
    346         bs->signature = host2uint16_t_be(0x55AA);
     386        if (cfg->fat_type == FAT32) {
     387                bs->sec_per_fat = 0;
     388                bs->fat32.sectors_per_fat = host2uint32_t_le(cfg->fat_sectors);
     389
     390                bs->fat32.pdn = 0x80;
     391                bs->fat32.ebs = 0x29;
     392                bs->fat32.id = host2uint32_t_be(0x12345678);
     393                bs->fat32.root_cluster = 2;
     394
     395                memcpy(bs->fat32.label, "HELENOS_NEW", 11);
     396                memcpy(bs->fat32.type, "FAT32   ", 8);
     397        } else {
     398                bs->sec_per_fat = host2uint16_t_le(cfg->fat_sectors);
     399                bs->pdn = 0x80;
     400                bs->ebs = 0x29;
     401                bs->id = host2uint32_t_be(0x12345678);
     402
     403                memcpy(bs->label, "HELENOS_NEW", 11);
     404                memcpy(bs->type, "FAT   ", 8);
     405        }
    347406}
    348407
  • uspace/app/mkmfs/Makefile

    r2bdf8313 rb0f00a9  
    2828#
    2929
    30 USPACE_PREFIX = ../../..
    31 EXTRA_CFLAGS = -Iinclude
    32 BINARY = char_ms
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBMINIX_PREFIX)
     33BINARY = mkmfs
    3334
    3435SOURCES = \
    35         proto/ps2.c \
    36         char_mouse.c \
    37         chardev.c
     36        mkmfs.c
    3837
    3938include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/pcc/cc/cc/Makefile

    r2bdf8313 rb0f00a9  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
     2# Copyright (c) 2011 Jiri Zarevucky
    43# All rights reserved.
    54#
     
    2928
    3029USPACE_PREFIX = ../../../..
    31 ROOT_PATH = $(USPACE_PREFIX)/..
    32 LIBS = $(LIBNET_PREFIX)/libnet.a
    33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
     30MIPDIR = ../../mip
     31ARCHDIR = ../../arch/$(PLATFORM)
     32OSDIR = ../../os/helenos
     33EXTRA_CFLAGS = -I$(MIPDIR) -I$(ARCHDIR) -I$(OSDIR) -w
     34DEFS = -Dmach_$(PLATFORM) -D__helenos__
     35BINARY = cc
    3436
    35 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
    36 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
     37PRE_DEPEND = compat.c
     38EXTRA_CLEAN = compat.c
    3739
    38 -include $(COMMON_MAKEFILE)
    39 -include $(CONFIG_MAKEFILE)
    40 
    41 BINARY = lo
     40POSIX_COMPAT = y
    4241
    4342SOURCES = \
    44         lo.c
     43        cc.c \
     44        compat.c
    4545
    4646include $(USPACE_PREFIX)/Makefile.common
     47
     48compat.c: $(MIPDIR)/compat.c
     49        ln -s -f $^ $@
     50
  • uspace/app/ping/ping.c

    r2bdf8313 rb0f00a9  
    340340            config.dest_str, config.size, config.size);
    341341       
    342         int icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT);
    343         if (icmp_phone < 0) {
     342        async_sess_t *sess = icmp_connect_module();
     343        if (!sess) {
    344344                fprintf(stderr, "%s: Unable to connect to ICMP service (%s)\n", NAME,
    345                     str_error(icmp_phone));
    346                 return icmp_phone;
     345                    str_error(errno));
     346                return errno;
    347347        }
    348348       
     
    355355                            str_error(ret));
    356356                       
    357                         async_hangup(icmp_phone);
     357                        async_hangup(sess);
    358358                        return ret;
    359359                }
    360360               
    361361                /* Ping! */
    362                 int result = icmp_echo_msg(icmp_phone, config.size, config.timeout,
     362                int result = icmp_echo_msg(sess, config.size, config.timeout,
    363363                    config.ttl, config.tos, !config.fragments, config.dest_raw,
    364364                    config.dest_len);
     
    370370                            str_error(ret));
    371371                       
    372                         async_hangup(icmp_phone);
     372                        async_hangup(sess);
    373373                        return ret;
    374374                }
     
    390390        }
    391391       
    392         async_hangup(icmp_phone);
     392        async_hangup(sess);
    393393       
    394394        return 0;
  • uspace/app/redir/redir.c

    r2bdf8313 rb0f00a9  
    4949static void usage(void)
    5050{
    51         printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
     51        fprintf(stderr, "Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
    5252            NAME);
    5353}
     
    8383        args = (const char **) calloc(argc + 1, sizeof(char *));
    8484        if (!args) {
    85                 printf("No memory available\n");
     85                fprintf(stderr, "No memory available\n");
    8686                return 0;
    8787        }
     
    9898       
    9999        if (rc != EOK) {
    100                 printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
     100                fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, argv[0],
    101101                    str_error(rc));
     102                return 0;
    102103        }
    103104       
  • uspace/app/sbi/src/compat.h

    r2bdf8313 rb0f00a9  
    3838#ifdef __HELENOS__
    3939
     40#define list sbi_list
     41#define list_t sbi_list_t
     42
    4043/*
    4144 * Avoid name conflicts with ADT library.
     
    4447#define list_prepend sbi_list_prepend
    4548#define list_remove sbi_list_remove
     49#define list_first sbi_list_first
     50#define list_last sbi_list_last
    4651
    4752#endif
  • uspace/app/sbi/src/input.c

    r2bdf8313 rb0f00a9  
    176176int input_get_line(input_t *input, char **line)
    177177{
     178        const char *prompt;
    178179        const char *sp;
    179180        char *dp;
     
    212213                /* Interactive mode */
    213214                if (input->line_no == 0)
    214                         printf("sbi> ");
     215                        prompt = "sbi> ";
    215216                else
    216                         printf("...  ");
     217                        prompt = "...  ";
    217218
    218219                fflush(stdout);
    219                 if (os_input_line(&line_p) != EOK)
     220                if (os_input_line(prompt, &line_p) != EOK)
    220221                        return EIO;
    221222
  • uspace/app/sbi/src/list_t.h

    r2bdf8313 rb0f00a9  
    3030#define LIST_T_H_
    3131
     32#include "compat.h"
     33
    3234typedef struct list_node {
    3335        struct list_node *prev, *next;
  • uspace/app/sbi/src/os/helenos.c

    r2bdf8313 rb0f00a9  
    210210 * @param ptr   Place to store pointer to new string.
    211211 */
    212 int os_input_line(char **ptr)
     212int os_input_line(const char *prompt, char **ptr)
    213213{
    214214        char *line;
     
    219219                if (tinput == NULL)
    220220                        return EIO;
     221
     222                tinput_set_prompt(tinput, prompt);
    221223        }
    222224
  • uspace/app/sbi/src/os/os.h

    r2bdf8313 rb0f00a9  
    3838char *os_chr_to_astr(wchar_t chr);
    3939void os_input_disp_help(void);
    40 int os_input_line(char **ptr);
     40int os_input_line(const char *prompt, char **ptr);
    4141int os_exec(char * const cmd[]);
    4242
  • uspace/app/sbi/src/os/posix.c

    r2bdf8313 rb0f00a9  
    193193 * @param ptr   Place to store pointer to new string.
    194194 */
    195 int os_input_line(char **ptr)
    196 {
     195int os_input_line(const char *prompt, char **ptr)
     196{
     197        printf("%s", prompt);
     198
    197199        if (fgets(os_input_buffer, OS_INPUT_BUFFER_SIZE, stdin) == NULL)
    198200                os_input_buffer[0] = '\0';
  • uspace/app/sysinfo/sysinfo.c

    r2bdf8313 rb0f00a9  
    5151        int rc;
    5252        char *ipath;
    53         sysinfo_item_tag_t tag;
     53        sysinfo_item_val_type_t tag;
    5454
    5555        if (argc != 2) {
     
    6060        ipath = argv[1];
    6161
    62         tag = sysinfo_get_tag(ipath);
     62        tag = sysinfo_get_val_type(ipath);
    6363
    6464        /* Silence warning */
     
    7575        case SYSINFO_VAL_DATA:
    7676                rc = print_item_data(ipath);
     77                break;
     78        default:
     79                printf("Error: Sysinfo item '%s' with unknown value type.\n",
     80                    ipath);
     81                rc = 2;
    7782                break;
    7883        }
  • uspace/app/taskdump/elf_core.c

    r2bdf8313 rb0f00a9  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838 * Looking at core files produced by Linux, these don't have section headers,
    3939 * only program headers, although objdump shows them as having sections.
    40  * Basically at the beginning there should be a note segment (which we
    41  * do not write) and one loadable segment per memory area (which we do write).
    42  *
    43  * The note segment probably contains register state, etc. -- we don't
    44  * deal with these yet. Nevertheless you can use these core files with
    45  * objdump or gdb.
    46  */
    47 
     40 * Basically at the beginning there should be a note segment followed
     41 * by one loadable segment per memory area.
     42 *
     43 * The note segment contains a series of records with register state,
     44 * process info etc. We only write one record NT_PRSTATUS which contains
     45 * process/register state (anything which is not register state we fill
     46 * with zeroes).
     47 */
     48
     49#include <align.h>
     50#include <elf/elf.h>
     51#include <elf/elf_linux.h>
    4852#include <stdio.h>
    4953#include <stdlib.h>
     
    5862#include <udebug.h>
    5963#include <macros.h>
    60 
    61 #include <elf.h>
    62 #include "include/elf_core.h"
    63 
    64 static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size);
    65 static int write_all(int fd, void *data, size_t len);
    66 static int write_mem_area(int fd, as_area_info_t *area, int phoneid);
     64#include <libarch/istate.h>
     65
     66#include "elf_core.h"
     67
     68static off64_t align_foff_up(off64_t, uintptr_t, size_t);
     69static int align_pos(int, size_t);
     70static int write_mem_area(int, as_area_info_t *, async_sess_t *);
    6771
    6872#define BUFFER_SIZE 0x1000
     
    7175/** Save ELF core file.
    7276 *
    73  * @param file_name     Name of file to save to.
    74  * @param ainfo         Array of @a n memory area info structures.
    75  * @param n             Number of memory areas.
    76  * @param phoneid       Debugging phone.
    77  *
    78  * @return              EOK on sucess, ENOENT if file cannot be created,
    79  *                      ENOMEM on out of memory, EIO on write error.
    80  */
    81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid)
     77 * @param file_name Name of file to save to.
     78 * @param ainfo     Array of @a n memory area info structures.
     79 * @param n         Number of memory areas.
     80 * @param sess      Debugging session.
     81 *
     82 * @return EOK on sucess.
     83 * @return ENOENT if file cannot be created.
     84 * @return ENOMEM on out of memory.
     85 * @return EIO on write error.
     86 *
     87 */
     88int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n,
     89    async_sess_t *sess, istate_t *istate)
    8290{
    8391        elf_header_t elf_hdr;
     
    8694        elf_word flags;
    8795        elf_segment_header_t *p_hdr;
     96        elf_prstatus_t pr_status;
     97        elf_note_t note;
     98        size_t word_size;
    8899
    89100        int fd;
    90         int rc;
     101        ssize_t rc;
    91102        unsigned int i;
    92103
    93         n_ph = n;
    94 
    95         p_hdr = malloc(sizeof(elf_segment_header_t) * n);
     104#ifdef __32_BITS__
     105        word_size = 4;
     106#endif
     107#ifdef __64_BITS__
     108        /*
     109         * This should be 8 per the 64-bit ELF spec, but the Linux kernel
     110         * screws up and uses 4 anyway (and screws up elf_note_t as well)
     111         * and we are trying to be compatible with Linux GDB target. Sigh.
     112         */
     113        word_size = 4;
     114#endif
     115        memset(&pr_status, 0, sizeof(pr_status));
     116        istate_to_elf_regs(istate, &pr_status.regs);
     117
     118        n_ph = n + 1;
     119
     120        p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph);
    96121        if (p_hdr == NULL) {
    97122                printf("Failed allocating memory.\n");
     
    111136         *      ELF header
    112137         *      program headers
     138         *      note segment
    113139         * repeat:
    114140         *      (pad for alignment)
    115          *      segment data
     141         *      core segment
    116142         * end repeat
    117143         */
     
    143169        foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t);
    144170
    145         for (i = 1; i <= n; ++i) {
    146                 foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE);
     171        memset(&p_hdr[0], 0, sizeof(p_hdr[0]));
     172        p_hdr[0].p_type = PT_NOTE;
     173        p_hdr[0].p_offset = foff;
     174        p_hdr[0].p_vaddr = 0;
     175        p_hdr[0].p_paddr = 0;
     176        p_hdr[0].p_filesz = sizeof(elf_note_t)
     177            + ALIGN_UP((str_size("CORE") + 1), word_size)
     178            + ALIGN_UP(sizeof(elf_prstatus_t), word_size);
     179        p_hdr[0].p_memsz = 0;
     180        p_hdr[0].p_flags = 0;
     181        p_hdr[0].p_align = 1;
     182
     183        foff += p_hdr[0].p_filesz;
     184
     185        for (i = 0; i < n; ++i) {
     186                foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE);
    147187
    148188                flags = 0;
    149                 if (ainfo[i - 1].flags & AS_AREA_READ)
     189                if (ainfo[i].flags & AS_AREA_READ)
    150190                        flags |= PF_R;
    151                 if (ainfo[i - 1].flags & AS_AREA_WRITE)
     191                if (ainfo[i].flags & AS_AREA_WRITE)
    152192                        flags |= PF_W;
    153                 if (ainfo[i - 1].flags & AS_AREA_EXEC)
     193                if (ainfo[i].flags & AS_AREA_EXEC)
    154194                        flags |= PF_X;
    155195
    156                 memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i - 1]));
    157                 p_hdr[i - 1].p_type = PT_LOAD;
    158                 p_hdr[i - 1].p_offset = foff;
    159                 p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;
    160                 p_hdr[i - 1].p_paddr = 0;
    161                 p_hdr[i - 1].p_filesz = ainfo[i - 1].size;
    162                 p_hdr[i - 1].p_memsz = ainfo[i - 1].size;
    163                 p_hdr[i - 1].p_flags = flags;
    164                 p_hdr[i - 1].p_align = PAGE_SIZE;
    165 
    166                 foff += ainfo[i - 1].size;
     196                memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1]));
     197                p_hdr[i + 1].p_type = PT_LOAD;
     198                p_hdr[i + 1].p_offset = foff;
     199                p_hdr[i + 1].p_vaddr = ainfo[i].start_addr;
     200                p_hdr[i + 1].p_paddr = 0;
     201                p_hdr[i + 1].p_filesz = ainfo[i].size;
     202                p_hdr[i + 1].p_memsz = ainfo[i].size;
     203                p_hdr[i + 1].p_flags = flags;
     204                p_hdr[i + 1].p_align = PAGE_SIZE;
     205
     206                foff += ainfo[i].size;
    167207        }
    168208
    169209        rc = write_all(fd, &elf_hdr, sizeof(elf_hdr));
    170         if (rc != EOK) {
     210        if (rc != sizeof(elf_hdr)) {
    171211                printf("Failed writing ELF header.\n");
    172212                free(p_hdr);
     
    176216        for (i = 0; i < n_ph; ++i) {
    177217                rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i]));
    178                 if (rc != EOK) {
     218                if (rc != sizeof(p_hdr[i])) {
    179219                        printf("Failed writing program header.\n");
    180220                        free(p_hdr);
     
    183223        }
    184224
    185         for (i = 0; i < n_ph; ++i) {
     225        if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
     226                printf("Failed writing memory data.\n");
     227                free(p_hdr);
     228                return EIO;
     229        }
     230
     231        /*
     232         * Write note header
     233         */
     234        note.namesz = str_size("CORE") + 1;
     235        note.descsz = sizeof(elf_prstatus_t);
     236        note.type = NT_PRSTATUS;
     237
     238        rc = write_all(fd, &note, sizeof(elf_note_t));
     239        if (rc != sizeof(elf_note_t)) {
     240                printf("Failed writing note header.\n");
     241                free(p_hdr);
     242                return EIO;
     243        }
     244
     245        rc = write_all(fd, "CORE", note.namesz);
     246        if (rc != (ssize_t) note.namesz) {
     247                printf("Failed writing note header.\n");
     248                free(p_hdr);
     249                return EIO;
     250        }
     251
     252        rc = align_pos(fd, word_size);
     253        if (rc != EOK) {
     254                printf("Failed writing note header.\n");
     255                free(p_hdr);
     256                return EIO;
     257        }
     258
     259        rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t));
     260        if (rc != sizeof(elf_prstatus_t)) {
     261                printf("Failed writing register data.\n");
     262                free(p_hdr);
     263                return EIO;
     264        }
     265
     266        for (i = 1; i < n_ph; ++i) {
    186267                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    187268                        printf("Failed writing memory data.\n");
     
    189270                        return EIO;
    190271                }
    191                 if (write_mem_area(fd, &ainfo[i], phoneid) != EOK) {
     272                if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
    192273                        printf("Failed writing memory data.\n");
    193274                        free(p_hdr);
     
    206287        off64_t rva = vaddr % page_size;
    207288        off64_t rfo = foff % page_size;
    208        
     289
    209290        if (rva >= rfo)
    210291                return (foff + (rva - rfo));
    211        
     292
    212293        return (foff + (page_size + (rva - rfo)));
    213294}
     
    215296/** Write memory area from application to core file.
    216297 *
    217  * @param fd            File to write to.
    218  * @param area          Memory area info structure.
    219  * @param phoneid       Debugging phone.
    220  *
    221  * @return              EOK on success, EIO on failure.
    222  */
    223 static int write_mem_area(int fd, as_area_info_t *area, int phoneid)
     298 * @param fd   File to write to.
     299 * @param area Memory area info structure.
     300 * @param sess Debugging session.
     301 *
     302 * @return EOK on success, EIO on failure.
     303 *
     304 */
     305static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
    224306{
    225307        size_t to_copy;
    226308        size_t total;
    227309        uintptr_t addr;
    228         int rc;
     310        ssize_t rc;
    229311
    230312        addr = area->start_addr;
     
    233315        while (total < area->size) {
    234316                to_copy = min(area->size - total, BUFFER_SIZE);
    235                 rc = udebug_mem_read(phoneid, buffer, addr, to_copy);
     317                rc = udebug_mem_read(sess, buffer, addr, to_copy);
    236318                if (rc < 0) {
    237319                        printf("Failed reading task memory.\n");
     
    240322
    241323                rc = write_all(fd, buffer, to_copy);
    242                 if (rc != EOK) {
     324                if (rc != (ssize_t) to_copy) {
    243325                        printf("Failed writing memory contents.\n");
    244326                        return EIO;
     
    252334}
    253335
    254 /** Write until the buffer is written in its entirety.
    255  *
    256  * This function fails if it cannot write exactly @a len bytes to the file.
    257  *
    258  * @param fd            The file to write to.
    259  * @param buf           Data, @a len bytes long.
    260  * @param len           Number of bytes to write.
    261  *
    262  * @return              EOK on error, return value from write() if writing
    263  *                      failed.
    264  */
    265 static int write_all(int fd, void *data, size_t len)
     336static int align_pos(int fd, size_t align)
    266337{
    267         int cnt = 0;
    268 
    269         do {
    270                 data += cnt;
    271                 len -= cnt;
    272                 cnt = write(fd, data, len);
    273         } while (cnt > 0 && (len - cnt) > 0);
    274 
    275         if (cnt < 0)
    276                 return cnt;
    277 
    278         if (len - cnt > 0)
    279                 return EIO;
     338        off64_t cur_pos;
     339        size_t rem, adv;
     340
     341        cur_pos = lseek(fd, 0, SEEK_CUR);
     342        if (cur_pos < 0)
     343                return -1;
     344
     345        rem = cur_pos % align;
     346        adv = align - rem;
     347
     348        cur_pos = lseek(fd, adv, SEEK_CUR);
     349        if (cur_pos < 0)
     350                return -1;
    280351
    281352        return EOK;
    282353}
    283354
    284 
    285355/** @}
    286356 */
  • uspace/app/taskdump/include/elf_core.h

    r2bdf8313 rb0f00a9  
    3636#define ELF_CORE_H_
    3737
    38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid);
     38#include <async.h>
     39#include <elf/elf_linux.h>
     40#include <libarch/istate.h>
     41
     42extern int elf_core_save(const char *, as_area_info_t *, unsigned int,
     43    async_sess_t *, istate_t *);
    3944
    4045#endif
  • uspace/app/taskdump/include/symtab.h

    r2bdf8313 rb0f00a9  
    3636#define SYMTAB_H_
    3737
     38#include <elf/elf.h>
    3839#include <sys/types.h>
    39 #include <elf.h>
    4040
    4141typedef struct {
  • uspace/app/taskdump/symtab.c

    r2bdf8313 rb0f00a9  
    3636 */
    3737
     38#include <elf/elf.h>
    3839#include <stdio.h>
    3940#include <stdlib.h>
     
    4344#include <fcntl.h>
    4445
    45 #include <elf.h>
    4646#include "include/symtab.h"
    4747
     
    5050    elf_section_header_t *shdr);
    5151static int chunk_load(int fd, off64_t start, size_t size, void **ptr);
    52 static int read_all(int fd, void *buf, size_t len);
    5352
    5453/** Load symbol table from an ELF file.
     
    9089
    9190        rc = read_all(fd, &elf_hdr, sizeof(elf_header_t));
    92         if (rc != EOK) {
     91        if (rc != sizeof(elf_header_t)) {
    9392                printf("failed reading elf header\n");
    9493                free(stab);
     
    312311
    313312        rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t));
    314         if (rc != EOK)
     313        if (rc != sizeof(elf_section_header_t))
    315314                return EIO;
    316315
     
    331330static int chunk_load(int fd, off64_t start, size_t size, void **ptr)
    332331{
    333         int rc;
    334 
    335         rc = lseek(fd, start, SEEK_SET);
    336         if (rc == (off64_t) -1) {
     332        ssize_t rc;
     333        off64_t offs;
     334
     335        offs = lseek(fd, start, SEEK_SET);
     336        if (offs == (off64_t) -1) {
    337337                printf("failed seeking chunk\n");
    338338                *ptr = NULL;
     
    347347
    348348        rc = read_all(fd, *ptr, size);
    349         if (rc != EOK) {
     349        if (rc != (ssize_t) size) {
    350350                printf("failed reading chunk\n");
    351351                free(*ptr);
     
    357357}
    358358
    359 /** Read until the buffer is read in its entirety.
    360  *
    361  * This function fails if it cannot read exactly @a len bytes from the file.
    362  *
    363  * @param fd            The file to read from.
    364  * @param buf           Buffer for storing data, @a len bytes long.
    365  * @param len           Number of bytes to read.
    366  *
    367  * @return              EOK on error, EIO if file is short or return value
    368  *                      from read() if reading failed.
    369  */
    370 static int read_all(int fd, void *buf, size_t len)
    371 {
    372         int cnt = 0;
    373 
    374         do {
    375                 buf += cnt;
    376                 len -= cnt;
    377                 cnt = read(fd, buf, len);
    378         } while (cnt > 0 && (len - cnt) > 0);
    379 
    380         if (cnt < 0)
    381                 return cnt;
    382 
    383         if (len - cnt > 0)
    384                 return EIO;
    385 
    386         return EOK;
    387 }
    388 
    389359/** @}
    390360 */
  • uspace/app/taskdump/taskdump.c

    r2bdf8313 rb0f00a9  
    3434
    3535#include <async.h>
     36#include <elf/elf_linux.h>
    3637#include <stdio.h>
    3738#include <stdlib.h>
     
    5455#define LINE_BYTES 16
    5556
    56 static int phoneid;
     57static async_sess_t *sess;
    5758static task_id_t task_id;
    5859static bool write_core_file;
     
    7374static char *fmt_sym_address(uintptr_t addr);
    7475
     76static istate_t reg_state;
     77
    7578int main(int argc, char *argv[])
    7679{
     
    104107                printf("Failed dumping address space areas.\n");
    105108
    106         udebug_end(phoneid);
    107         async_hangup(phoneid);
     109        udebug_end(sess);
     110        async_hangup(sess);
    108111
    109112        return 0;
     
    112115static int connect_task(task_id_t task_id)
    113116{
    114         int rc;
    115 
    116         rc = async_connect_kbox(task_id);
    117 
    118         if (rc == ENOTSUP) {
    119                 printf("You do not have userspace debugging support "
    120                     "compiled in the kernel.\n");
    121                 printf("Compile kernel with 'Support for userspace debuggers' "
    122                     "(CONFIG_UDEBUG) enabled.\n");
    123                 return rc;
    124         }
    125 
    126         if (rc < 0) {
     117        async_sess_t *ksess = async_connect_kbox(task_id);
     118       
     119        if (!ksess) {
     120                if (errno == ENOTSUP) {
     121                        printf("You do not have userspace debugging support "
     122                            "compiled in the kernel.\n");
     123                        printf("Compile kernel with 'Support for userspace debuggers' "
     124                            "(CONFIG_UDEBUG) enabled.\n");
     125                        return errno;
     126                }
     127               
    127128                printf("Error connecting\n");
    128                 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, rc);
    129                 return rc;
    130         }
    131 
    132         phoneid = rc;
    133 
    134         rc = udebug_begin(phoneid);
     129                printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno);
     130                return errno;
     131        }
     132       
     133        int rc = udebug_begin(ksess);
    135134        if (rc < 0) {
    136135                printf("udebug_begin() -> %d\n", rc);
    137136                return rc;
    138137        }
    139 
     138       
     139        sess = ksess;
    140140        return 0;
    141141}
     
    213213
    214214        /* TODO: See why NULL does not work. */
    215         rc = udebug_thread_read(phoneid, &dummy_buf, 0, &copied, &needed);
     215        rc = udebug_thread_read(sess, &dummy_buf, 0, &copied, &needed);
    216216        if (rc < 0) {
    217217                printf("udebug_thread_read() -> %d\n", rc);
     
    227227        thash_buf = malloc(buf_size);
    228228
    229         rc = udebug_thread_read(phoneid, thash_buf, buf_size, &copied, &needed);
     229        rc = udebug_thread_read(sess, thash_buf, buf_size, &copied, &needed);
    230230        if (rc < 0) {
    231231                printf("udebug_thread_read() -> %d\n", rc);
     
    262262        int rc;
    263263
    264         rc = udebug_areas_read(phoneid, &dummy_buf, 0, &copied, &needed);
     264        rc = udebug_areas_read(sess, &dummy_buf, 0, &copied, &needed);
    265265        if (rc < 0) {
    266266                printf("udebug_areas_read() -> %d\n", rc);
     
    271271        ainfo_buf = malloc(buf_size);
    272272
    273         rc = udebug_areas_read(phoneid, ainfo_buf, buf_size, &copied, &needed);
     273        rc = udebug_areas_read(sess, ainfo_buf, buf_size, &copied, &needed);
    274274        if (rc < 0) {
    275275                printf("udebug_areas_read() -> %d\n", rc);
     
    296296        if (write_core_file) {
    297297                printf("Writing core file '%s'\n", core_file_name);
    298                 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);
     298
     299                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess,
     300                    &reg_state);
     301
    299302                if (rc != EOK) {
    300303                        printf("Failed writing core file.\n");
     
    316319        int rc;
    317320
    318         rc = udebug_regs_read(phoneid, thash, &istate);
     321        rc = udebug_regs_read(sess, thash, &istate);
    319322        if (rc < 0) {
    320323                printf("Failed reading registers (%d).\n", rc);
     
    324327        pc = istate_get_pc(&istate);
    325328        fp = istate_get_fp(&istate);
     329
     330        /* Save register state for dumping to core file later. */
     331        reg_state = istate;
    326332
    327333        sym_pc = fmt_sym_address(pc);
     
    359365        (void) arg;
    360366
    361         rc = udebug_mem_read(phoneid, &data, addr, sizeof(data));
     367        rc = udebug_mem_read(sess, &data, addr, sizeof(data));
    362368        if (rc < 0) {
    363369                printf("Warning: udebug_mem_read() failed.\n");
     
    430436        int rc;
    431437
    432         rc = udebug_name_read(phoneid, &dummy_buf, 0, &copied, &needed);
     438        rc = udebug_name_read(sess, &dummy_buf, 0, &copied, &needed);
    433439        if (rc < 0)
    434440                return NULL;
     
    436442        name_size = needed;
    437443        name = malloc(name_size + 1);
    438         rc = udebug_name_read(phoneid, name, name_size, &copied, &needed);
     444        rc = udebug_name_read(sess, name, name_size, &copied, &needed);
    439445        if (rc < 0) {
    440446                free(name);
  • uspace/app/tester/Makefile

    r2bdf8313 rb0f00a9  
    2929
    3030USPACE_PREFIX = ../..
     31LIBS = $(LIBEXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX)
    3133BINARY = tester
    3234
    3335SOURCES = \
    3436        tester.c \
     37        util.c \
    3538        thread/thread1.c \
    3639        print/print1.c \
     
    5255        mm/malloc2.c \
    5356        mm/malloc3.c \
    54         devs/devman1.c \
     57        mm/mapping1.c \
    5558        hw/misc/virtchar1.c \
    56         hw/serial/serial1.c
     59        hw/serial/serial1.c \
     60        libext2/libext2_1.c
    5761
    5862include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/console/console1.c

    r2bdf8313 rb0f00a9  
    5050{
    5151        if (!test_quiet) {
     52                console_ctrl_t *console = console_init(stdin, stdout);
     53               
    5254                printf("Style test: ");
    53                 fflush(stdout);
    54                 console_set_style(fphone(stdout), STYLE_NORMAL);
     55                console_flush(console);
     56                console_set_style(console, STYLE_NORMAL);
    5557                printf(" normal ");
    56                 fflush(stdout);
    57                 console_set_style(fphone(stdout), STYLE_EMPHASIS);
     58                console_flush(console);
     59                console_set_style(console, STYLE_EMPHASIS);
    5860                printf(" emphasized ");
    59                 fflush(stdout);
    60                 console_set_style(fphone(stdout), STYLE_INVERTED);
     61                console_flush(console);
     62                console_set_style(console, STYLE_INVERTED);
    6163                printf(" inverted ");
    62                 fflush(stdout);
    63                 console_set_style(fphone(stdout), STYLE_SELECTED);
     64                console_flush(console);
     65                console_set_style(console, STYLE_SELECTED);
    6466                printf(" selected ");
    65                 fflush(stdout);
    66                 console_set_style(fphone(stdout), STYLE_NORMAL);
     67                console_flush(console);
     68                console_set_style(console, STYLE_NORMAL);
    6769                printf("\n");
    6870               
     
    7375                for (j = 0; j < 2; j++) {
    7476                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    75                                 fflush(stdout);
    76                                 console_set_color(fphone(stdout), i, COLOR_WHITE,
     77                                console_flush(console);
     78                                console_set_color(console, COLOR_WHITE, i,
    7779                                    j ? CATTR_BRIGHT : 0);
    7880                                printf(" %s ", color_name[i]);
    7981                        }
    80                         fflush(stdout);
    81                         console_set_style(fphone(stdout), STYLE_NORMAL);
     82                        console_flush(console);
     83                        console_set_style(console, STYLE_NORMAL);
    8284                        putchar('\n');
    8385                }
     
    8688                for (j = 0; j < 2; j++) {
    8789                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    88                                 fflush(stdout);
    89                                 console_set_color(fphone(stdout), COLOR_WHITE, i,
     90                                console_flush(console);
     91                                console_set_color(console, i, COLOR_WHITE,
    9092                                    j ? CATTR_BRIGHT : 0);
    9193                                printf(" %s ", color_name[i]);
    9294                        }
    93                         fflush(stdout);
    94                         console_set_style(fphone(stdout), STYLE_NORMAL);
     95                        console_flush(console);
     96                        console_set_style(console, STYLE_NORMAL);
    9597                        putchar('\n');
    9698                }
     
    99101               
    100102                for (i = 0; i < 255; i += 16) {
    101                         fflush(stdout);
    102                         console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
     103                        console_flush(console);
     104                        console_set_rgb_color(console, i << 16, (255 - i) << 16);
    103105                        putchar('X');
    104106                }
    105                 fflush(stdout);
    106                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     107                console_flush(console);
     108                console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0);
    107109                putchar('\n');
    108110               
    109111                for (i = 0; i < 255; i += 16) {
    110                         fflush(stdout);
    111                         console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
     112                        console_flush(console);
     113                        console_set_rgb_color(console, i << 8, (255 - i) << 8);
    112114                        putchar('X');
    113115                }
    114                 fflush(stdout);
    115                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     116                console_flush(console);
     117                console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0);
    116118                putchar('\n');
    117119               
    118120                for (i = 0; i < 255; i += 16) {
    119                         fflush(stdout);
    120                         console_set_rgb_color(fphone(stdout), 255 - i, i);
     121                        console_flush(console);
     122                        console_set_rgb_color(console, i, 255 - i);
    121123                        putchar('X');
    122124                }
    123                 fflush(stdout);
    124                 console_set_style(fphone(stdout), STYLE_NORMAL);
     125                console_flush(console);
     126                console_set_style(console, STYLE_NORMAL);
    125127                putchar('\n');
    126128        }
  • uspace/app/tester/hw/misc/virtchar1.c

    r2bdf8313 rb0f00a9  
    4343#include <str.h>
    4444#include <vfs/vfs.h>
     45#include <vfs/vfs_sess.h>
    4546#include <sys/stat.h>
    4647#include <fcntl.h>
    4748#include "../../tester.h"
    4849
    49 #define DEVICE_PATH_NORMAL "/dev/devices/\\virt\\null\\a"
    50 #define DEVICE_PATH_CLASSES "/dev/class/virt-null\\1"
     50#define DEVICE_PATH_NORMAL "/loc/devices/\\virt\\null\\a"
    5151#define BUFFER_SIZE 64
    5252
     
    6666        TPRINTF("   ...file handle %d\n", fd);
    6767
    68         TPRINTF(" Asking for phone...\n");
    69         int phone = fd_phone(fd);
    70         if (phone < 0) {
     68        TPRINTF(" Asking for session...\n");
     69        async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     70        if (!sess) {
    7171                close(fd);
    72                 TPRINTF("   ...error: %s\n", str_error(phone));
    73                 return "Failed to get phone to device";
     72                TPRINTF("   ...error: %s\n", str_error(errno));
     73                return "Failed to get session to device";
    7474        }
    75         TPRINTF("   ...phone is %d\n", phone);
     75        TPRINTF("   ...session is %p\n", sess);
    7676       
    7777        TPRINTF(" Will try to read...\n");
    7878        size_t i;
    7979        char buffer[BUFFER_SIZE];
    80         char_dev_read(phone, buffer, BUFFER_SIZE);
     80        char_dev_read(sess, buffer, BUFFER_SIZE);
    8181        TPRINTF(" ...verifying that we read zeroes only...\n");
    8282        for (i = 0; i < BUFFER_SIZE; i++) {
     
    8888       
    8989        /* Clean-up. */
    90         TPRINTF(" Closing phones and file descriptors\n");
    91         async_hangup(phone);
     90        TPRINTF(" Closing session and file descriptor\n");
     91        async_hangup(sess);
    9292        close(fd);
    9393       
     
    104104        }
    105105
    106         res = test_virtchar1_internal(DEVICE_PATH_CLASSES);
    107         if (res != NULL) {
    108                 return res;
    109         }
    110 
    111106        return NULL;
    112107}
  • uspace/app/tester/hw/serial/serial1.c

    r2bdf8313 rb0f00a9  
    7171                }
    7272       
    73         int res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING);
    74        
    7573        devman_handle_t handle;
    76         res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
     74        int res = devman_fun_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
    7775            IPC_FLAG_BLOCKING);
    7876        if (res != EOK)
    7977                return "Could not get serial device handle";
    8078       
    81         int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING);
    82         if (phone < 0) {
    83                 devman_hangup_phone(DEVMAN_CLIENT);
     79        async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
     80            IPC_FLAG_BLOCKING);
     81        if (!sess)
    8482                return "Unable to connect to serial device";
    85         }
    8683       
    8784        char *buf = (char *) malloc(cnt + 1);
    8885        if (buf == NULL) {
    89                 async_hangup(phone);
    90                 devman_hangup_phone(DEVMAN_CLIENT);
     86                async_hangup(sess);
    9187                return "Failed to allocate input buffer";
    9288        }
     
    9793        sysarg_t old_word_size;
    9894       
    99         res = async_req_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud,
     95        async_exch_t *exch = async_exchange_begin(sess);
     96        res = async_req_0_4(exch, SERIAL_GET_COM_PROPS, &old_baud,
    10097            &old_par, &old_word_size, &old_stop);
     98        async_exchange_end(exch);
     99       
    101100        if (res != EOK) {
    102101                free(buf);
    103                 async_hangup(phone);
    104                 devman_hangup_phone(DEVMAN_CLIENT);
     102                async_hangup(sess);
    105103                return "Failed to get old serial communication parameters";
    106104        }
    107105       
    108         res = async_req_4_0(phone, SERIAL_SET_COM_PROPS, 1200,
     106        exch = async_exchange_begin(sess);
     107        res = async_req_4_0(exch, SERIAL_SET_COM_PROPS, 1200,
    109108            SERIAL_NO_PARITY, 8, 1);
     109        async_exchange_end(exch);
     110       
    110111        if (EOK != res) {
    111112                free(buf);
    112                 async_hangup(phone);
    113                 devman_hangup_phone(DEVMAN_CLIENT);
     113                async_hangup(sess);
    114114                return "Failed to set serial communication parameters";
    115115        }
     
    120120        size_t total = 0;
    121121        while (total < cnt) {
    122                 ssize_t read = char_dev_read(phone, buf, cnt - total);
     122                ssize_t read = char_dev_read(sess, buf, cnt - total);
    123123               
    124124                if (read < 0) {
    125                         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     125                        exch = async_exchange_begin(sess);
     126                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    126127                            old_par, old_word_size, old_stop);
     128                        async_exchange_end(exch);
     129                       
    127130                        free(buf);
    128                         async_hangup(phone);
    129                         devman_hangup_phone(DEVMAN_CLIENT);
     131                        async_hangup(sess);
    130132                        return "Failed read from serial device";
    131133                }
    132134               
    133135                if ((size_t) read > cnt - total) {
    134                         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     136                        exch = async_exchange_begin(sess);
     137                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    135138                            old_par, old_word_size, old_stop);
     139                        async_exchange_end(exch);
     140                       
    136141                        free(buf);
    137                         async_hangup(phone);
    138                         devman_hangup_phone(DEVMAN_CLIENT);
     142                        async_hangup(sess);
    139143                        return "Read more data than expected";
    140144                }
     
    151155                         * direction of data transfer.
    152156                         */
    153                         ssize_t written = char_dev_write(phone, buf, read);
     157                        ssize_t written = char_dev_write(sess, buf, read);
    154158                       
    155159                        if (written < 0) {
    156                                 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     160                                exch = async_exchange_begin(sess);
     161                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    157162                                    old_par, old_word_size, old_stop);
     163                                async_exchange_end(exch);
     164                               
    158165                                free(buf);
    159                                 async_hangup(phone);
    160                                 devman_hangup_phone(DEVMAN_CLIENT);
     166                                async_hangup(sess);
    161167                                return "Failed write to serial device";
    162168                        }
    163169                       
    164170                        if (written != read) {
    165                                 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     171                                exch = async_exchange_begin(sess);
     172                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    166173                                    old_par, old_word_size, old_stop);
     174                                async_exchange_end(exch);
     175                               
    167176                                free(buf);
    168                                 async_hangup(phone);
    169                                 devman_hangup_phone(DEVMAN_CLIENT);
     177                                async_hangup(sess);
    170178                                return "Written less data than read from serial device";
    171179                        }
     
    180188       
    181189        size_t eot_size = str_size(EOT);
    182         ssize_t written = char_dev_write(phone, (void *) EOT, eot_size);
    183        
    184         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     190        ssize_t written = char_dev_write(sess, (void *) EOT, eot_size);
     191       
     192        exch = async_exchange_begin(sess);
     193        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    185194            old_par, old_word_size, old_stop);
     195        async_exchange_end(exch);
     196       
    186197        free(buf);
    187         async_hangup(phone);
    188         devman_hangup_phone(DEVMAN_CLIENT);
     198        async_hangup(sess);
    189199       
    190200        if (written < 0)
  • uspace/app/tester/ipc/ping_pong.c

    r2bdf8313 rb0f00a9  
    3030#include <stdlib.h>
    3131#include <sys/time.h>
    32 #include <ipc/ns.h>
     32#include <ns.h>
    3333#include <async.h>
    3434#include <errno.h>
     
    6161                size_t i;
    6262                for (i = 0; i < COUNT_GRANULARITY; i++) {
    63                         int retval = async_req_0_0(PHONE_NS, NS_PING);
     63                        int retval = ns_ping();
    6464                       
    6565                        if (retval != EOK) {
  • uspace/app/tester/mm/common.c

    r2bdf8313 rb0f00a9  
    7373        link_t *link;
    7474       
    75         while ((link = list_head(&mem_blocks)) != NULL) {
     75        while ((link = list_first(&mem_blocks)) != NULL) {
    7676                mem_block_t *block = list_get_instance(link, mem_block_t, link);
    7777                free_block(block);
    7878        }
    7979       
    80         while ((link = list_head(&mem_areas)) != NULL) {
     80        while ((link = list_first(&mem_areas)) != NULL) {
    8181                mem_area_t *area = list_get_instance(link, mem_area_t, link);
    8282                unmap_area(area);
  • uspace/app/tester/print/print2.c

    r2bdf8313 rb0f00a9  
    4545        TPRINTF("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5);
    4646       
     47        TPRINTF("Testing printf(\"%%lld %%3.2lld %%-3.2lld %%2.3lld %%-2.3lld\", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5):\n");
     48        TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n");
     49        TPRINTF("Real output:     [%lld] [%3.2lld] [%-3.2lld] [%2.3lld] [%-2.3lld]\n\n", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5);
     50       
    4751        TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n");
    4852        TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n");
  • uspace/app/tester/stdio/stdio1.c

    r2bdf8313 rb0f00a9  
    3939{
    4040        FILE *file;
    41         const char *file_name = "/readme";
     41        const char *file_name = "/textdemo";
    4242       
    4343        TPRINTF("Open file \"%s\"...", file_name);
  • uspace/app/tester/tester.c

    r2bdf8313 rb0f00a9  
    6464#include "mm/malloc2.def"
    6565#include "mm/malloc3.def"
     66#include "mm/mapping1.def"
    6667#include "hw/serial/serial1.def"
    6768#include "hw/misc/virtchar1.def"
    68 #include "devs/devman1.def"
     69#include "libext2/libext2_1.def"
    6970        {NULL, NULL, NULL, false}
    7071};
  • uspace/app/tester/tester.h

    r2bdf8313 rb0f00a9  
    9797extern const char *test_malloc2(void);
    9898extern const char *test_malloc3(void);
     99extern const char *test_mapping1(void);
    99100extern const char *test_serial1(void);
    100101extern const char *test_virtchar1(void);
     102extern const char *test_libext2_1(void);
    101103extern const char *test_devman1(void);
     104extern const char *test_devman2(void);
    102105
    103106extern test_t tests[];
  • uspace/app/tester/vfs/vfs1.c

    r2bdf8313 rb0f00a9  
    3535#include <fcntl.h>
    3636#include <dirent.h>
    37 #include <devmap.h>
     37#include <loc.h>
    3838#include <sys/types.h>
    3939#include <sys/stat.h>
  • uspace/app/tetris/Makefile

    r2bdf8313 rb0f00a9  
    3434        shapes.c \
    3535        scores.c \
    36         input.c \
    3736        tetris.c \
    3837        screen.c
  • uspace/app/tetris/scores.c

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray Exp $ */
    2 /*      $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $   */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)scores.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * scores.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd
     33 * OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    6068#include <err.h>
    6169#include <time.h>
    62 
    6370#include "screen.h"
    6471#include "tetris.h"
     
    118125        int j;
    119126        size_t off;
    120         console_event_t ev;
     127        kbd_event_t ev;
    121128       
    122129        clear_screen();
     
    133140       
    134141        while (1) {
    135                 fflush(stdout);
    136                 if (!console_get_event(fphone(stdin), &ev))
     142                console_flush(console);
     143                if (!console_get_kbd_event(console, &ev))
    137144                        exit(1);
    138145               
  • uspace/app/tetris/scores.h

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * scores.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd
     33 * OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)scores.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
     
    4149/** @file
    4250 */
    43 
    4451
    4552/*
  • uspace/app/tetris/screen.c

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray Exp $ */
    2 /*      $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $       */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)screen.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * screen.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft
     33 * OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    6977static const struct shape *lastshape;
    7078
     79static suseconds_t timeleft = 0;
     80
     81console_ctrl_t *console;
     82
    7183
    7284/*
     
    8294static void start_standout(uint32_t color)
    8395{
    84         fflush(stdout);
    85         console_set_rgb_color(fphone(stdout), 0xffffff,
    86             use_color ? color : 0x000000);
     96        console_flush(console);
     97        console_set_rgb_color(console, use_color ? color : 0x000000,
     98            0xffffff);
    8799}
    88100
    89101static void resume_normal(void)
    90102{
    91         fflush(stdout);
    92         console_set_style(fphone(stdout), STYLE_NORMAL);
     103        console_flush(console);
     104        console_set_style(console, STYLE_NORMAL);
    93105}
    94106
    95107void clear_screen(void)
    96108{
    97         console_clear(fphone(stdout));
     109        console_clear(console);
    98110        moveto(0, 0);
    99111}
     
    105117{
    106118        resume_normal();
    107         console_clear(fphone(stdout));
     119        console_clear(console);
    108120        curscore = -1;
    109121        memset(curscreen, 0, sizeof(curscreen));
     
    115127void scr_init(void)
    116128{
    117         console_cursor_visibility(fphone(stdout), 0);
     129        console_cursor_visibility(console, 0);
    118130        resume_normal();
    119131        scr_clear();
     
    122134void moveto(sysarg_t r, sysarg_t c)
    123135{
    124         fflush(stdout);
    125         console_set_pos(fphone(stdout), c, r);
     136        console_flush(console);
     137        console_set_pos(console, c, r);
    126138}
    127139
     
    130142static int get_display_size(winsize_t *ws)
    131143{
    132         return console_get_size(fphone(stdout), &ws->ws_col, &ws->ws_row);
     144        return console_get_size(console, &ws->ws_col, &ws->ws_row);
    133145}
    134146
     
    136148{
    137149        sysarg_t ccap;
    138         int rc = console_get_color_cap(fphone(stdout), &ccap);
     150        int rc = console_get_color_cap(console, &ccap);
    139151       
    140152        if (rc != 0)
    141153                return false;
    142154       
    143         return (ccap >= CONSOLE_CCAP_RGB);
     155        return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
    144156}
    145157
     
    179191void scr_end(void)
    180192{
    181         console_cursor_visibility(fphone(stdout), 1);
     193        console_cursor_visibility(console, 1);
    182194}
    183195
     
    302314                resume_normal();
    303315       
    304         fflush(stdout);
     316        console_flush(console);
    305317}
    306318
     
    322334}
    323335
     336/** Sleep for the current turn time
     337 *
     338 * Eat any input that might be available.
     339 *
     340 */
     341void tsleep(void)
     342{
     343        suseconds_t timeout = fallrate;
     344       
     345        while (timeout > 0) {
     346                kbd_event_t event;
     347               
     348                if (!console_get_kbd_event_timeout(console, &event, &timeout))
     349                        break;
     350        }
     351}
     352
     353/** Get char with timeout
     354 *
     355 */
     356int tgetchar(void)
     357{
     358        /*
     359         * Reset timeleft to fallrate whenever it is not positive
     360         * and increase speed.
     361         */
     362       
     363        if (timeleft <= 0) {
     364                faster();
     365                timeleft = fallrate;
     366        }
     367       
     368        /*
     369         * Wait to see if there is any input. If so, take it and
     370         * update timeleft so that the next call to tgetchar()
     371         * will not wait as long. If there is no input,
     372         * make timeleft zero and return -1.
     373         */
     374       
     375        wchar_t c = 0;
     376       
     377        while (c == 0) {
     378                kbd_event_t event;
     379               
     380                if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
     381                        timeleft = 0;
     382                        return -1;
     383                }
     384               
     385                if (event.type == KEY_PRESS)
     386                        c = event.c;
     387        }
     388       
     389        return (int) c;
     390}
     391
     392/** Get char without timeout
     393 *
     394 */
     395int twait(void)
     396{
     397        wchar_t c = 0;
     398       
     399        while (c == 0) {
     400                kbd_event_t event;
     401               
     402                if (!console_get_kbd_event(console, &event))
     403                        return -1;
     404               
     405                if (event.type == KEY_PRESS)
     406                        c = event.c;
     407        }
     408       
     409        return (int) c;
     410}
     411
    324412/** @}
    325413 */
  • uspace/app/tetris/screen.h

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * screen.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd
     33 * OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)screen.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
     
    4856
    4957#include <sys/types.h>
     58#include <io/console.h>
    5059#include <async.h>
    5160#include <bool.h>
     
    5665} winsize_t;
    5766
     67extern console_ctrl_t *console;
    5868extern winsize_t winsize;
    5969
     
    6171extern void clear_screen(void);
    6272
    63 /* just calls putchar; for tputs */
    6473extern int put(int);
    6574extern void scr_clear(void);
     
    7079extern void scr_update(void);
    7180
     81extern void tsleep(void);
     82extern int tgetchar(void);
     83extern int twait(void);
     84
    7285/** @}
    7386 */
  • uspace/app/tetris/shapes.c

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt Exp $      */
    2 /*      $NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * shapes.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd
     33 * OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)shapes.c    8.1 (Berkeley) 5/31/93
    3644 */
    3745
     
    6169
    6270const struct shape shapes[] = {
    63         /*  0 */  {  7,  7, { TL, TC, MR }, 0xff042d},
    64         /*  1 */  {  8,  8, { TC, TR, ML }, 0xff9304},
    65         /*  2 */  {  9, 11, { ML, MR, BC }, 0xbeff04},
    66         /*  3 */  {  3,  3, { TL, TC, ML }, 0x63ff04},
    67         /*  4 */  { 12, 14, { ML, BL, MR }, 0xce04ff},
    68         /*  5 */  { 15, 17, { ML, BR, MR }, 0xff04cf},
    69         /*  6 */  { 18, 18, { ML, MR, 2  }, 0x7604ff},  /* sticks out */
    70         /*  7 */  {  0,  0, { TC, ML, BL }, 0xff042d},
    71         /*  8 */  {  1,  1, { TC, MR, BR }, 0xff9304},
    72         /*  9 */  { 10,  2, { TC, MR, BC }, 0xbeff04},
    73         /* 10 */  { 11,  9, { TC, ML, MR }, 0xbeff04},
    74         /* 11 */  {  2, 10, { TC, ML, BC }, 0xbeff04},
    75         /* 12 */  { 13,  4, { TC, BC, BR }, 0xce04ff},
    76         /* 13 */  { 14, 12, { TR, ML, MR }, 0xce04ff},
    77         /* 14 */  {  4, 13, { TL, TC, BC }, 0xce04ff},
    78         /* 15 */  { 16,  5, { TR, TC, BC }, 0xff04cf},
    79         /* 16 */  { 17, 15, { TL, MR, ML }, 0xff04cf},
    80         /* 17 */  {  5, 16, { TC, BC, BL }, 0xff04cf},
    81         /* 18 */  {  6,  6, { TC, BC, 2 * B_COLS }, 0x7604ff}  /* sticks out */
     71        /*  0 */  {  7,  7, { TL, TC, MR }, 0x00aaaa},
     72        /*  1 */  {  8,  8, { TC, TR, ML }, 0x00aa00},
     73        /*  2 */  {  9, 11, { ML, MR, BC }, 0xaa5500},
     74        /*  3 */  {  3,  3, { TL, TC, ML }, 0x0000aa},
     75        /*  4 */  { 12, 14, { ML, BL, MR }, 0xaa00aa},
     76        /*  5 */  { 15, 17, { ML, BR, MR }, 0xffa500},
     77        /*  6 */  { 18, 18, { ML, MR, 2  }, 0xaa0000},  /* sticks out */
     78        /*  7 */  {  0,  0, { TC, ML, BL }, 0x00aaaa},
     79        /*  8 */  {  1,  1, { TC, MR, BR }, 0x00aa00},
     80        /*  9 */  { 10,  2, { TC, MR, BC }, 0xaa5500},
     81        /* 10 */  { 11,  9, { TC, ML, MR }, 0xaa5500},
     82        /* 11 */  {  2, 10, { TC, ML, BC }, 0xaa5500},
     83        /* 12 */  { 13,  4, { TC, BC, BR }, 0xaa00aa},
     84        /* 13 */  { 14, 12, { TR, ML, MR }, 0xaa00aa},
     85        /* 14 */  {  4, 13, { TL, TC, BC }, 0xaa00aa},
     86        /* 15 */  { 16,  5, { TR, TC, BC }, 0xffa500},
     87        /* 16 */  { 17, 15, { TL, MR, ML }, 0xffa500},
     88        /* 17 */  {  5, 16, { TC, BC, BL }, 0xffa500},
     89        /* 18 */  {  6,  6, { TC, BC, 2 * B_COLS }, 0xaa0000}  /* sticks out */
    8290};
    8391
  • uspace/app/tetris/tetris.c

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */
    2 /*      $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $   */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)tetris.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * tetris.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd
     33 * OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    5664#include <unistd.h>
    5765#include <getopt.h>
    58 
    59 #include "input.h"
    6066#include "scores.h"
    6167#include "screen.h"
     
    245251        int ch;
    246252       
     253        console = console_init(stdin, stdout);
     254       
    247255        keys = "jkl pq";
    248256       
    249257        classic = 0;
    250         showpreview = 1; 
     258        showpreview = 1;
    251259       
    252260        while ((ch = getopt(argc, argv, "ck:ps")) != -1)
     
    283291                for (j = i + 1; j <= 5; j++) {
    284292                        if (keys[i] == keys[j])
    285                                 errx(1, "duplicate command keys specified.");
     293                                errx(1, "%s", "duplicate command keys specified.");
    286294                }
    287295               
     
    371379                                        scr_msg(key_msg, 0);
    372380                                        scr_msg(msg, 1);
    373                                         (void) fflush(stdout);
    374                                 } while (rwait((struct timeval *) NULL) == -1);
     381                                        console_flush(console);
     382                                } while (!twait());
    375383                               
    376384                                scr_msg(msg, 0);
  • uspace/app/tetris/tetris.h

    r2bdf8313 rb0f00a9  
    1 /*      $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * tetris.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd
     33 * OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)tetris.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
  • uspace/app/top/Makefile

    r2bdf8313 rb0f00a9  
    3333SOURCES = \
    3434        top.c \
    35         screen.c \
    36         input.c
     35        screen.c
    3736
    3837include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/top/screen.c

    r2bdf8313 rb0f00a9  
    4646#include "top.h"
    4747
     48#define USEC_COUNT  1000000
     49
    4850static sysarg_t warn_col = 0;
    4951static sysarg_t warn_row = 0;
     52static suseconds_t timeleft = 0;
     53
     54console_ctrl_t *console;
    5055
    5156static void screen_style_normal(void)
    5257{
    53         fflush(stdout);
    54         console_set_style(fphone(stdout), STYLE_NORMAL);
     58        console_flush(console);
     59        console_set_style(console, STYLE_NORMAL);
    5560}
    5661
    5762static void screen_style_inverted(void)
    5863{
    59         fflush(stdout);
    60         console_set_style(fphone(stdout), STYLE_INVERTED);
     64        console_flush(console);
     65        console_set_style(console, STYLE_INVERTED);
    6166}
    6267
    6368static void screen_moveto(sysarg_t col, sysarg_t row)
    6469{
    65         fflush(stdout);
    66         console_set_pos(fphone(stdout), col, row);
     70        console_flush(console);
     71        console_set_pos(console, col, row);
    6772}
    6873
    6974static void screen_get_pos(sysarg_t *col, sysarg_t *row)
    7075{
    71         fflush(stdout);
    72         console_get_pos(fphone(stdout), col, row);
     76        console_flush(console);
     77        console_get_pos(console, col, row);
    7378}
    7479
    7580static void screen_get_size(sysarg_t *col, sysarg_t *row)
    7681{
    77         fflush(stdout);
    78         console_get_size(fphone(stdout), col, row);
     82        console_flush(console);
     83        console_get_size(console, col, row);
    7984}
    8085
     
    8489       
    8590        if (clear) {
    86                 fflush(stdout);
    87                 console_clear(fphone(stdout));
     91                console_flush(console);
     92                console_clear(console);
    8893        }
    8994       
     
    111116void screen_init(void)
    112117{
    113         fflush(stdout);
    114         console_cursor_visibility(fphone(stdout), false);
     118        console = console_init(stdin, stdout);
     119       
     120        console_flush(console);
     121        console_cursor_visibility(console, false);
    115122       
    116123        screen_restart(true);
     
    121128        screen_restart(true);
    122129       
    123         fflush(stdout);
    124         console_cursor_visibility(fphone(stdout), true);
     130        console_flush(console);
     131        console_cursor_visibility(console, true);
    125132}
    126133
     
    508515        }
    509516       
    510         fflush(stdout);
     517        console_flush(console);
    511518}
    512519
     
    521528       
    522529        screen_newline();
    523         fflush(stdout);
     530        console_flush(console);
     531}
     532
     533/** Get char with timeout
     534 *
     535 */
     536int tgetchar(unsigned int sec)
     537{
     538        /*
     539         * Reset timeleft whenever it is not positive.
     540         */
     541       
     542        if (timeleft <= 0)
     543                timeleft = sec * USEC_COUNT;
     544       
     545        /*
     546         * Wait to see if there is any input. If so, take it and
     547         * update timeleft so that the next call to tgetchar()
     548         * will not wait as long. If there is no input,
     549         * make timeleft zero and return -1.
     550         */
     551       
     552        wchar_t c = 0;
     553       
     554        while (c == 0) {
     555                kbd_event_t event;
     556               
     557                if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
     558                        timeleft = 0;
     559                        return -1;
     560                }
     561               
     562                if (event.type == KEY_PRESS)
     563                        c = event.c;
     564        }
     565       
     566        return (int) c;
    524567}
    525568
  • uspace/app/top/screen.h

    r2bdf8313 rb0f00a9  
    3535#define TOP_SCREEN_H_
    3636
     37#include <io/console.h>
    3738#include "top.h"
     39
     40extern console_ctrl_t *console;
    3841
    3942extern void screen_init(void);
     
    4245extern void print_warning(const char *, ...);
    4346
     47extern int tgetchar(unsigned int);
     48
    4449#endif
    4550
  • uspace/app/top/top.c

    r2bdf8313 rb0f00a9  
    4242#include <thread.h>
    4343#include <sys/time.h>
    44 #include <arch/barrier.h>
    4544#include <errno.h>
    4645#include <sort.h>
    4746#include "screen.h"
    48 #include "input.h"
    4947#include "top.h"
    5048
  • uspace/app/trace/ipc_desc.c

    r2bdf8313 rb0f00a9  
    3333 */
    3434
    35 #include <ipc/common.h>
     35#include <abi/ipc/methods.h>
    3636#include <stdlib.h>
    3737#include "ipc_desc.h"
     
    3939ipc_m_desc_t ipc_methods[] = {
    4040        /* System methods */
    41         { IPC_M_CONNECT_TO_ME,  "CONNECT_TO_ME" },
    42         { IPC_M_CONNECT_ME_TO,  "CONNECT_ME_TO" },
    43         { IPC_M_PHONE_HUNGUP,   "PHONE_HUNGUP" },
    44         { IPC_M_SHARE_OUT,      "SHARE_OUT" },
    45         { IPC_M_SHARE_IN,       "SHARE_IN" },
    46         { IPC_M_DATA_WRITE,     "DATA_WRITE" },
    47         { IPC_M_DATA_READ,      "DATA_READ" },
    48         { IPC_M_DEBUG_ALL,      "DEBUG_ALL" },
    49 
    50         /* Well-known methods */
    51         { IPC_M_PING,           "PING" },
    52 
     41        { IPC_M_PHONE_HUNGUP,  "PHONE_HUNGUP" },
     42        { IPC_M_CONNECT_ME,    "CONNECT_ME" },
     43        { IPC_M_CONNECT_ME_TO, "CONNECT_ME_TO" },
     44        { IPC_M_CONNECT_TO_ME, "CONNECT_TO_ME" },
     45        { IPC_M_SHARE_OUT,     "SHARE_OUT" },
     46        { IPC_M_SHARE_IN,      "SHARE_IN" },
     47        { IPC_M_DATA_WRITE,    "DATA_WRITE" },
     48        { IPC_M_DATA_READ,     "DATA_READ" },
     49        { IPC_M_DEBUG,         "DEBUG" },
     50       
    5351        /* Terminating entry */
    5452        { 0, NULL }
  • uspace/app/trace/ipcp.c

    r2bdf8313 rb0f00a9  
    3737#include <adt/hash_table.h>
    3838#include <sys/typefmt.h>
    39 
     39#include <abi/ipc/methods.h>
    4040#include "ipc_desc.h"
    4141#include "proto.h"
     
    268268        proto_t *proto;
    269269        int cphone;
    270 
     270       
    271271        sysarg_t *resp;
    272272        oper_t *oper;
    273273        int i;
    274 
    275 //      printf("parse_answer\n");
    276 
     274       
    277275        phone = pcall->phone_hash;
    278276        method = IPC_GET_IMETHOD(pcall->question);
    279277        retval = IPC_GET_RETVAL(*answer);
    280 
     278       
    281279        resp = answer->args;
    282 
     280       
    283281        if ((display_mask & DM_IPC) != 0) {
    284282                printf("Response to %p: retval=%" PRIdn ", args = (%" PRIun ", "
     
    288286                    IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
    289287        }
    290 
     288       
    291289        if ((display_mask & DM_USER) != 0) {
    292290                oper = pcall->oper;
    293 
    294                 if (oper != NULL && (oper->rv_type != V_VOID || oper->respc > 0)) {
     291               
     292                if ((oper != NULL) &&
     293                    ((oper->rv_type != V_VOID) || (oper->respc > 0))) {
    295294                        printf("->");
    296 
     295                       
    297296                        if (oper->rv_type != V_VOID) {
    298297                                putchar(' ');
     
    304303                                putchar('(');
    305304                                for (i = 1; i <= oper->respc; ++i) {
    306                                         if (i > 1) printf(", ");
     305                                        if (i > 1)
     306                                                printf(", ");
    307307                                        val_print(resp[i], oper->resp_type[i - 1]);
    308308                                }
    309309                                putchar(')');
    310310                        }
    311 
     311                       
    312312                        putchar('\n');
    313313                }
    314314        }
    315 
    316         if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) {
     315       
     316        if ((phone == PHONE_NS) && (method == IPC_M_CONNECT_ME_TO) &&
     317            (retval == 0)) {
    317318                /* Connected to a service (through NS) */
    318319                service = IPC_GET_ARG1(pcall->question);
    319320                proto = proto_get_by_srv(service);
    320                 if (proto == NULL) proto = proto_unknown;
    321 
     321                if (proto == NULL)
     322                        proto = proto_unknown;
     323               
    322324                cphone = IPC_GET_ARG5(*answer);
    323325                if ((display_mask & DM_SYSTEM) != 0) {
    324326                        printf("Registering connection (phone %d, protocol: %s)\n", cphone,
    325                                 proto->name);
    326                 }
     327                    proto->name);
     328                }
     329               
    327330                ipcp_connection_set(cphone, 0, proto);
    328331        }
     
    334337        pending_call_t *pcall;
    335338        unsigned long key[1];
    336 
    337 //      printf("ipcp_call_in()\n");
    338 
     339       
    339340        if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) {
    340341                /* Not a response */
     
    344345                return;
    345346        }
    346 
     347       
    347348        hash = hash & ~IPC_CALLID_ANSWERED;
    348349        key[0] = hash;
    349 
     350       
    350351        item = hash_table_find(&pending_calls, key);
    351         if (item == NULL) return; // No matching question found
    352 
     352        if (item == NULL)
     353                return; /* No matching question found */
     354       
    353355        /*
    354356         * Response matched to question.
     
    357359        pcall = hash_table_get_instance(item, pending_call_t, link);
    358360        hash_table_remove(&pending_calls, key, 1);
    359 
     361       
    360362        parse_answer(hash, pcall, call);
    361363        free(pcall);
  • uspace/app/trace/syscalls.c

    r2bdf8313 rb0f00a9  
    3333 */
    3434
    35 #include <kernel/syscall/syscall.h>
     35#include <abi/syscall.h>
    3636#include "syscalls.h"
    3737#include "trace.h"
     
    4040    [SYS_KLOG] ={ "klog",                               3,      V_INT_ERRNO },
    4141    [SYS_TLS_SET] = { "tls_set",                        1,      V_ERRNO },
     42
    4243    [SYS_THREAD_CREATE] = { "thread_create",            3,      V_ERRNO },
    4344    [SYS_THREAD_EXIT] = { "thread_exit",                1,      V_ERRNO },
     
    7475    [SYS_UNREGISTER_IRQ] = { "unregister_irq",  2,      V_ERRNO },
    7576
    76     [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",                2,      V_INTEGER },
     77    [SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type",              2,      V_INTEGER },
    7778    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",            3,      V_ERRNO },
    7879    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",    3,      V_ERRNO },
    7980    [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data",              5,      V_ERRNO },
    8081
    81     [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0,   V_ERRNO },
     82    [SYS_DEBUG_ACTIVATE_CONSOLE] = { "debug_activate_console", 0,       V_ERRNO },
    8283    [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox",      1,      V_ERRNO }
    8384};
  • uspace/app/trace/trace.c

    r2bdf8313 rb0f00a9  
    5050#include <sys/types.h>
    5151#include <sys/typefmt.h>
     52#include <vfs/vfs.h>
    5253
    5354#include <libc.h>
     
    7273ipc_call_t thread_ipc_req[THBUF_SIZE];
    7374
    74 int phoneid;
     75async_sess_t *sess;
    7576bool abort_trace;
    7677
     
    8182
    8283static bool cev_valid;
    83 static console_event_t cev;
     84static kbd_event_t cev;
    8485
    8586void thread_trace_start(uintptr_t thread_hash);
    8687
    87 static proto_t *proto_console;
    8888static task_id_t task_id;
    8989static loader_t *task_ldr;
     
    146146static int connect_task(task_id_t task_id)
    147147{
    148         int rc;
    149 
    150         rc = async_connect_kbox(task_id);
    151 
    152         if (rc == ENOTSUP) {
    153                 printf("You do not have userspace debugging support "
    154                     "compiled in the kernel.\n");
    155                 printf("Compile kernel with 'Support for userspace debuggers' "
    156                     "(CONFIG_UDEBUG) enabled.\n");
    157                 return rc;
    158         }
    159 
    160         if (rc < 0) {
     148        async_sess_t *ksess = async_connect_kbox(task_id);
     149       
     150        if (!ksess) {
     151                if (errno == ENOTSUP) {
     152                        printf("You do not have userspace debugging support "
     153                            "compiled in the kernel.\n");
     154                        printf("Compile kernel with 'Support for userspace debuggers' "
     155                            "(CONFIG_UDEBUG) enabled.\n");
     156                        return errno;
     157                }
     158               
    161159                printf("Error connecting\n");
    162                 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
    163                 return rc;
    164         }
    165 
    166         phoneid = rc;
    167 
    168         rc = udebug_begin(phoneid);
     160                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
     161                return errno;
     162        }
     163       
     164        int rc = udebug_begin(ksess);
    169165        if (rc < 0) {
    170166                printf("udebug_begin() -> %d\n", rc);
    171167                return rc;
    172168        }
    173 
    174         rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
     169       
     170        rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
    175171        if (rc < 0) {
    176172                printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
    177173                return rc;
    178174        }
    179 
     175       
     176        sess = ksess;
    180177        return 0;
    181178}
     
    188185        int i;
    189186
    190         rc = udebug_thread_read(phoneid, thread_hash_buf,
     187        rc = udebug_thread_read(sess, thread_hash_buf,
    191188                THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
    192189        if (rc < 0) {
     
    314311
    315312        memset(&call, 0, sizeof(call));
    316         rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
     313        rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args));
    317314
    318315        if (rc >= 0) {
     
    325322        ipc_call_t question, reply;
    326323        int rc;
    327         int phoneidx;
    328 
    329 //      printf("sc_ipc_call_sync_fast()\n");
    330         phoneidx = sc_args[0];
     324        int phoneid;
     325
     326        phoneid = sc_args[0];
    331327
    332328        IPC_SET_IMETHOD(question, sc_args[1]);
     
    337333        IPC_SET_ARG5(question, 0);
    338334
    339 //      printf("memset\n");
    340335        memset(&reply, 0, sizeof(reply));
    341 //      printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
    342 //              phoneid, &reply.args, sc_args[5], sizeof(reply.args));
    343         rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
    344 //      printf("dmr->%d\n", rc);
    345         if (rc < 0) return;
    346 
    347 //      printf("call ipc_call_sync\n");
    348         ipcp_call_sync(phoneidx, &question, &reply);
     336        rc = udebug_mem_read(sess, &reply.args, sc_args[5], sizeof(reply.args));
     337        if (rc < 0)
     338                return;
     339       
     340        ipcp_call_sync(phoneid, &question, &reply);
    349341}
    350342
     
    355347
    356348        memset(&question, 0, sizeof(question));
    357         rc = udebug_mem_read(phoneid, &question.args, sc_args[1],
     349        rc = udebug_mem_read(sess, &question.args, sc_args[1],
    358350            sizeof(question.args));
    359351
     
    372364
    373365        memset(&reply, 0, sizeof(reply));
    374         rc = udebug_mem_read(phoneid, &reply.args, sc_args[2],
     366        rc = udebug_mem_read(sess, &reply.args, sc_args[2],
    375367            sizeof(reply.args));
    376368
     
    391383
    392384        memset(&call, 0, sizeof(call));
    393         rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
    394 //      printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
    395 //              phoneid, (int)&call, sc_args[0], sizeof(call), rc);
    396 
    397         if (rc >= 0) {
     385        rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call));
     386       
     387        if (rc >= 0)
    398388                ipcp_call_in(&call, sc_rc);
    399         }
    400389}
    401390
     
    407396
    408397        /* Read syscall arguments */
    409         rc = udebug_args_read(phoneid, thread_hash, sc_args);
    410 
    411         async_serialize_start();
    412 
    413 //      printf("[%d] ", thread_id);
     398        rc = udebug_args_read(sess, thread_hash, sc_args);
    414399
    415400        if (rc < 0) {
    416401                printf("error\n");
    417                 async_serialize_end();
    418402                return;
    419403        }
     
    432416                break;
    433417        }
    434 
    435         async_serialize_end();
    436418}
    437419
     
    444426
    445427        /* Read syscall arguments */
    446         rc = udebug_args_read(phoneid, thread_hash, sc_args);
    447 
    448         async_serialize_start();
     428        rc = udebug_args_read(sess, thread_hash, sc_args);
    449429
    450430//      printf("[%d] ", thread_id);
     
    452432        if (rc < 0) {
    453433                printf("error\n");
    454                 async_serialize_end();
    455434                return;
    456435        }
     
    481460                break;
    482461        }
    483 
    484         async_serialize_end();
    485462}
    486463
    487464static void event_thread_b(uintptr_t hash)
    488465{
    489         async_serialize_start();
    490466        printf("New thread, hash %p\n", (void *) hash);
    491         async_serialize_end();
    492 
    493467        thread_trace_start(hash);
    494468}
     
    527501
    528502                /* Run thread until an event occurs */
    529                 rc = udebug_go(phoneid, thread_hash,
     503                rc = udebug_go(sess, thread_hash,
    530504                    &ev_type, &val0, &val1);
    531505
     
    612586
    613587        /* Send default files */
    614         fdi_node_t *files[4];
    615         fdi_node_t stdin_node;
    616         fdi_node_t stdout_node;
    617         fdi_node_t stderr_node;
    618        
    619         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    620                 files[0] = &stdin_node;
     588        int *files[4];
     589        int fd_stdin;
     590        int fd_stdout;
     591        int fd_stderr;
     592       
     593        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     594                files[0] = &fd_stdin;
    621595        else
    622596                files[0] = NULL;
    623597       
    624         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    625                 files[1] = &stdout_node;
     598        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     599                files[1] = &fd_stdout;
    626600        else
    627601                files[1] = NULL;
    628602       
    629         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    630                 files[2] = &stderr_node;
     603        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     604                files[2] = &fd_stderr;
    631605        else
    632606                files[2] = NULL;
     
    656630{
    657631        (void) arg;
    658 
     632       
     633        console_ctrl_t *console = console_init(stdin, stdout);
     634       
    659635        while (true) {
    660636                fibril_mutex_lock(&state_lock);
     
    662638                        fibril_condvar_wait(&state_cv, &state_lock);
    663639                fibril_mutex_unlock(&state_lock);
    664 
    665                 if (!console_get_event(fphone(stdin), &cev))
     640               
     641                if (!console_get_kbd_event(console, &cev))
    666642                        return -1;
    667 
     643               
    668644                fibril_mutex_lock(&state_lock);
    669645                cev_valid = true;
    670646                fibril_condvar_broadcast(&state_cv);
    671                 fibril_mutex_unlock(&state_lock);               
     647                fibril_mutex_unlock(&state_lock);
    672648        }
    673649}
     
    675651static void trace_task(task_id_t task_id)
    676652{
    677         console_event_t ev;
     653        kbd_event_t ev;
    678654        bool done;
    679655        int i;
     
    681657
    682658        ipcp_init();
    683 
    684         /*
    685          * User apps now typically have console on phone 3.
    686          * (Phones 1 and 2 are used by the loader).
    687          */
    688         ipcp_connection_set(3, 0, proto_console);
    689659
    690660        rc = get_thread_list();
     
    727697                case KC_P:
    728698                        printf("Pause...\n");
    729                         rc = udebug_stop(phoneid, thash);
     699                        rc = udebug_stop(sess, thash);
    730700                        if (rc != EOK)
    731701                                printf("Error: stop -> %d\n", rc);
     
    738708                        printf("Resume...\n");
    739709                        break;
     710                default:
     711                        break;
    740712                }
    741713        }
     
    743715        printf("\nTerminate debugging session...\n");
    744716        abort_trace = true;
    745         udebug_end(phoneid);
    746         async_hangup(phoneid);
     717        udebug_end(sess);
     718        async_hangup(sess);
    747719
    748720        ipcp_cleanup();
     
    785757        o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
    786758        proto_add_oper(p, VFS_IN_OPEN, o);
    787         o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);
    788         proto_add_oper(p, VFS_IN_OPEN_NODE, o);
    789759        o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
    790760        proto_add_oper(p, VFS_IN_READ, o);
     
    815785
    816786        proto_register(SERVICE_VFS, p);
    817 
    818         p = proto_new("console");
    819 
    820         o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
    821         proto_add_oper(p, VFS_IN_WRITE, o);
    822 
    823         resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
    824         resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR;
    825         o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def);
    826 
    827         arg_def[0] = V_CHAR;
    828         o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def);
    829         proto_add_oper(p, CONSOLE_CLEAR, o);
    830 
    831         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
    832         o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def);
    833         proto_add_oper(p, CONSOLE_GOTO, o);
    834 
    835         resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
    836         o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def);
    837         proto_add_oper(p, CONSOLE_GET_SIZE, o);
    838 
    839         arg_def[0] = V_INTEGER;
    840         o = oper_new("set_style", 1, arg_def, V_VOID, 0, resp_def);
    841         proto_add_oper(p, CONSOLE_SET_STYLE, o);
    842         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER;
    843         o = oper_new("set_color", 3, arg_def, V_VOID, 0, resp_def);
    844         proto_add_oper(p, CONSOLE_SET_COLOR, o);
    845         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
    846         o = oper_new("set_rgb_color", 2, arg_def, V_VOID, 0, resp_def);
    847         proto_add_oper(p, CONSOLE_SET_RGB_COLOR, o);
    848         o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def);
    849         proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);
    850 
    851         proto_console = p;
    852         proto_register(SERVICE_CONSOLE, p);
    853787}
    854788
Note: See TracChangeset for help on using the changeset viewer.