Changeset 00aece0 in mainline for uspace/app


Ignore:
Timestamp:
2012-02-18T16:47:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4449c6c
Parents:
bd5f3b7 (diff), f943dd3 (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:
236 added
41 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rbd5f3b7 r00aece0  
    3131LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \
    3232        $(LIBFMTUTIL_PREFIX)/libfmtutil.a
    33 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I$(LIBFMTUTIL_PREFIX)\
    34         -I. -Icmds/ -Icmds/builtins -Icmds/modules
     33EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) \
     34        -I$(LIBFMTUTIL_PREFIX) -I. -Icmds/ -Icmds/builtins -Icmds/modules
    3535BINARY = bdsh
    3636
     
    5151        cmds/modules/unmount/unmount.c \
    5252        cmds/modules/kcon/kcon.c \
     53        cmds/builtins/batch/batch.c \
    5354        cmds/builtins/exit/exit.c \
    5455        cmds/builtins/cd/cd.c \
  • uspace/app/bdsh/cmds/builtins/builtins.h

    rbd5f3b7 r00aece0  
    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/modules/cat/cat.c

    rbd5f3b7 r00aece0  
    103103{
    104104        console_set_pos(console, 0, console_rows-1);
    105         console_set_color(console, COLOR_BLUE, COLOR_WHITE, 0);
     105        console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0);
    106106       
    107107        printf("ENTER/SPACE/PAGE DOWN - next page, "
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rbd5f3b7 r00aece0  
    3333#include <str.h>
    3434#include <fcntl.h>
     35#include <sys/stat.h>
     36#include <dirent.h>
    3537#include "config.h"
    3638#include "util.h"
     
    5557};
    5658
     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
    5792static int strtoint(const char *s1)
    5893{
     
    67102        return (int) t1;
    68103}
     104
     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
    69318
    70319static int64_t copy_file(const char *src, const char *dest,
     
    127376        static char helpfmt[] =
    128377            "Usage:  %s [options] <source> <dest>\n"
    129             "Options: (* indicates not yet implemented)\n"
     378            "Options:\n"
    130379            "  -h, --help       A short option summary\n"
    131380            "  -v, --version    Print version information and exit\n"
    132             "* -V, --verbose    Be annoyingly noisy about what's being done\n"
    133             "* -f, --force      Do not complain when <dest> exists\n"
    134             "* -r, --recursive  Copy entire directories\n"
    135             "  -b, --buffer ## Set the read buffer size to ##\n"
    136             "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";
    137385        if (level == HELP_SHORT) {
    138386                printf("`%s' copies files and directories\n", cmdname);
    139387        } else {
    140388                help_cmd_cp(HELP_SHORT);
    141                 printf(helpfmt, cmdname, cmdname);
     389                printf(helpfmt, cmdname);
    142390        }
    143391
     
    148396{
    149397        unsigned int argc, verbose = 0;
    150         int buffer = 0;
     398        int buffer = 0, recursive = 0;
     399        int force = 0;
    151400        int c, opt_ind;
    152401        int64_t ret;
     
    167416                        break;
    168417                case 'f':
     418                        force = 1;
    169419                        break;
    170420                case 'r':
     421                        recursive = 1;
    171422                        break;
    172423                case 'b':
     
    194445        }
    195446
    196         ret = copy_file(argv[optind], argv[optind + 1], buffer, verbose);
    197 
    198         if (verbose)
    199                 printf("%" PRId64 " bytes copied\n", ret);
    200 
    201         if (ret >= 0)
     447        ret = do_copy(argv[optind], argv[optind + 1], buffer, verbose,
     448            recursive, force);
     449
     450        if (ret == 0)
    202451                return CMD_SUCCESS;
    203452        else
  • uspace/app/bdsh/cmds/modules/help/help.c

    rbd5f3b7 r00aece0  
    152152            "This is but a small glimpse of what you can do with HelenOS. "
    153153            "To learn more please point your browser to the HelenOS User's "
    154             "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n",
     154            "Guide: http://trac.helenos.org/wiki/UsersGuide\n\n",
    155155            ALIGN_LEFT);
    156156}
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rbd5f3b7 r00aece0  
    5454static struct option const long_options[] = {
    5555        {"size", required_argument, 0, 's'},
     56        {"sparse", no_argument, 0, 'p'},
    5657        {"help", no_argument, 0, 'h'},
    5758        {0, 0, 0, 0}
     
    6970                "  -h, --help       A short option summary\n"
    7071                "  -s, --size sz    Size of the file\n"
     72                "  -p, --sparse     Create a sparse file\n"
    7173                "\n"
    7274                "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n"
     
    115117        ssize_t file_size;
    116118        ssize_t total_written;
    117         ssize_t to_write, rc;
     119        ssize_t to_write, rc, rc2 = 0;
    118120        char *file_name;
    119121        void *buffer;
     122        bool create_sparse = false;
    120123
    121124        file_size = 0;
     
    124127
    125128        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    126                 c = getopt_long(argc, argv, "s:h", long_options, &opt_ind);
     129                c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind);
    127130                switch (c) {
    128131                case 'h':
    129132                        help_cmd_mkfile(HELP_LONG);
    130133                        return CMD_SUCCESS;
     134                case 'p':
     135                        create_sparse = true;
     136                        break;
    131137                case 's':
    132138                        file_size = read_size(optarg);
     
    154160                printf("%s: failed to create file %s.\n", cmdname, file_name);
    155161                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;
    156172        }
    157173
     
    174190        }
    175191
     192        free(buffer);
     193exit:
    176194        rc = close(fd);
    177         if (rc != 0) {
     195
     196        if (rc != 0 || rc2 < 0) {
    178197                printf("%s: Error writing file (%zd).\n", cmdname, rc);
    179198                return CMD_FAILURE;
    180199        }
    181 
    182         free(buffer);
    183200
    184201        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    rbd5f3b7 r00aece0  
    2727 */
    2828
     29#include <loc.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
    3132#include <vfs/vfs.h>
     33#include <adt/list.h>
    3234#include <errno.h>
    3335#include <getopt.h>
     36#include <inttypes.h>
    3437#include "config.h"
    3538#include "util.h"
     
    4346static struct option const long_options[] = {
    4447        { "help", no_argument, 0, 'h' },
     48        { "instance", required_argument, 0, 'i' },
    4549        { 0, 0, 0, 0 }
    4650};
     
    6165}
    6266
     67static void print_mtab_list(void)
     68{
     69        LIST_INITIALIZE(mtab_list);
     70        mtab_ent_t *old_ent = NULL;
     71        char *svc_name;
     72        int rc;
     73
     74        get_mtab_list(&mtab_list);
     75
     76        list_foreach(mtab_list, cur) {
     77                mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
     78                    link);
     79
     80                if (old_ent)
     81                        free(old_ent);
     82
     83                old_ent = mtab_ent;
     84
     85                printf("%s", mtab_ent->fs_name);
     86                if (mtab_ent->instance)
     87                        printf("/%d", mtab_ent->instance);
     88
     89                printf(" %s", mtab_ent->mp);
     90
     91                rc = loc_service_get_name(mtab_ent->service_id, &svc_name);
     92                if (rc == EOK) {
     93                        printf(" %s", svc_name);
     94                        free(svc_name);
     95                } else {
     96                        printf(" (%" PRIun ")", mtab_ent->service_id);
     97                }
     98
     99                if (str_size(mtab_ent->opts) > 0)
     100                        printf(" (%s)", mtab_ent->opts);
     101
     102                putchar('\n');
     103        }
     104
     105        if (old_ent)
     106                free(old_ent);
     107}
     108
    63109/* Main entry point for mount, accepts an array of arguments */
    64110int cmd_mount(char **argv)
     
    68114        const char *dev = "";
    69115        int rc, c, opt_ind;
     116        unsigned int instance = 0;
     117        bool instance_set = false;
     118        char **t_argv;
    70119
    71120        argc = cli_count_args(argv);
    72121
    73122        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    74                 c = getopt_long(argc, argv, "h", long_options, &opt_ind);
     123                c = getopt_long(argc, argv, "i:h", long_options, &opt_ind);
    75124                switch (c) {
    76125                case 'h':
    77126                        help_cmd_mount(HELP_LONG);
    78127                        return CMD_SUCCESS;
     128                case 'i':
     129                        instance = (unsigned int) strtol(optarg, NULL, 10);
     130                        instance_set = true;
     131                        break;
    79132                }
    80133        }
    81134
    82         if ((argc < 3) || (argc > 5)) {
     135        if (instance_set) {
     136                argc -= 2;
     137                t_argv = &argv[2];
     138        } else
     139                t_argv = &argv[0];
     140
     141        if ((argc == 2) || (argc > 5)) {
    83142                printf("%s: invalid number of arguments. Try `mount --help'\n",
    84143                    cmdname);
    85144                return CMD_FAILURE;
    86145        }
     146        if (argc == 1) {
     147                print_mtab_list();
     148                return CMD_SUCCESS;
     149        }
    87150        if (argc > 3)
    88                 dev = argv[3];
     151                dev = t_argv[3];
    89152        if (argc == 5)
    90                 mopts = argv[4];
     153                mopts = t_argv[4];
    91154
    92         rc = mount(argv[1], argv[2], dev, mopts, 0);
     155        rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
    93156        if (rc != EOK) {
    94157                printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
    95                     argv[1], argv[2], argv[3], rc);
     158                    t_argv[1], t_argv[2], t_argv[3], rc);
    96159                return CMD_FAILURE;
    97160        }
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rbd5f3b7 r00aece0  
    9595        if (NULL != rm->cwd)
    9696                free(rm->cwd);
    97 
    98         return;
    9997}
    10098
     
    129127                }
    130128        }
     129
     130        closedir(dirp);
    131131       
    132132        return ret;
  • uspace/app/bdsh/compl.c

    rbd5f3b7 r00aece0  
    9090{
    9191        compl_t *cs = NULL;
    92         size_t pref_size;
    9392        char *stext = NULL;
    9493        char *prefix = NULL;
    9594        char *dirname = NULL;
     95        int retval;
     96       
     97        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
     98        if (tokens == NULL) {
     99                retval = ENOMEM;
     100                goto error;
     101        }
     102       
     103        size_t pref_size;
    96104        char *rpath_sep;
    97105        static const char *dirlist_arg[] = { ".", NULL };
    98         int retval;
    99106        tokenizer_t tok;
    100         token_t tokens[WORD_MAX];
    101         int current_token;
     107        ssize_t current_token;
    102108        size_t tokens_length;
    103 
     109       
    104110        cs = calloc(1, sizeof(compl_t));
    105111        if (!cs) {
     
    107113                goto error;
    108114        }
    109 
     115       
    110116        /* Convert text buffer to string */
    111117        stext = wstr_to_astr(text);
     
    127133       
    128134        /* Find the current token */
    129         for (current_token = 0; current_token < (int) tokens_length;
     135        for (current_token = 0; current_token < (ssize_t) tokens_length;
    130136            current_token++) {
    131137                token_t *t = &tokens[current_token];
    132138                size_t end = t->char_start + t->char_length;
    133                 /* Check if the caret lies inside the token or immediately
     139               
     140                /*
     141                 * Check if the caret lies inside the token or immediately
    134142                 * after it
    135143                 */
     
    138146                }
    139147        }
    140         if (tokens_length == 0) current_token = -1;
    141        
    142         if (current_token >= 0 && tokens[current_token].type != TOKTYPE_SPACE) {
     148       
     149        if (tokens_length == 0)
     150                current_token = -1;
     151       
     152        if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE))
    143153                *cstart = tokens[current_token].char_start;
    144         }
    145         else {
     154        else
    146155                *cstart = pos;
    147         }
    148        
    149         /* Extract the prefix being completed
     156       
     157        /*
     158         * Extract the prefix being completed
    150159         * XXX: handle strings, etc.
    151160         */
     
    170179
    171180        /* Skip any whitespace before current token */
    172         int prev_token = current_token - 1;
    173         if (prev_token >= 0 && tokens[prev_token].type == TOKTYPE_SPACE) {
     181        ssize_t prev_token = current_token - 1;
     182        if ((prev_token >= 0) && (tokens[prev_token].type == TOKTYPE_SPACE))
    174183                prev_token--;
    175         }
    176 
     184       
    177185        /*
    178186         * It is a command if it is the first token or if it immediately
    179187         * follows a pipe token.
    180188         */
    181         if (prev_token < 0 || tokens[prev_token].type == TOKTYPE_SPACE)
     189        if ((prev_token < 0) || (tokens[prev_token].type == TOKTYPE_SPACE))
    182190                cs->is_command = true;
    183191        else
     
    254262        if (cs != NULL)
    255263                free(cs);
     264        if (tokens != NULL)
     265                free(tokens);
    256266
    257267        return retval;
  • uspace/app/bdsh/exec.c

    rbd5f3b7 r00aece0  
    134134                printf("%s: Failed waiting for command (%s)\n", progname,
    135135                    str_error(rc));
     136                return 1;
    136137        } else if (texit != TASK_EXIT_NORMAL) {
    137138                printf("%s: Command failed (unexpectedly terminated)\n", progname);
     139                return 1;
    138140        } else if (retval != 0) {
    139141                printf("%s: Command failed (exit code %d)\n",
    140142                    progname, retval);
     143                return 1;
    141144        }
    142145
  • uspace/app/bdsh/input.c

    rbd5f3b7 r00aece0  
    6767int process_input(cliuser_t *usr)
    6868{
    69         char *cmd[WORD_MAX];
    7069        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
    7170        if (tokens == NULL)
    7271                return ENOMEM;
     72       
     73        char *cmd[WORD_MAX];
    7374        int rc = 0;
    7475        tokenizer_t tok;
     
    7879        char *redir_to = NULL;
    7980
    80         if (NULL == usr->line) {
     81        if (usr->line == NULL) {
    8182                free(tokens);
    8283                return CL_EFAIL;
     
    195196                new_iostate.stdout = to;
    196197        }
    197        
     198
    198199        rc = run_command(cmd, usr, &new_iostate);
    199200       
  • uspace/app/devctl/devctl.c

    rbd5f3b7 r00aece0  
    3737#include <stdio.h>
    3838#include <stdlib.h>
     39#include <str_error.h>
    3940#include <sys/typefmt.h>
    4041
     
    4344#define MAX_NAME_LENGTH 1024
    4445
    45 static int fun_tree_print(devman_handle_t funh, int lvl)
     46static int fun_subtree_print(devman_handle_t funh, int lvl)
    4647{
    4748        char name[MAX_NAME_LENGTH];
     
    8485
    8586        for (i = 0; i < count; i++)
    86                 fun_tree_print(cfuns[i], lvl + 1);
     87                fun_subtree_print(cfuns[i], lvl + 1);
    8788
    8889        free(cfuns);
     
    9091}
    9192
    92 int main(int argc, char *argv[])
     93static int fun_tree_print(void)
    9394{
    9495        devman_handle_t root_fun;
     
    9899        if (rc != EOK) {
    99100                printf(NAME ": Error resolving root function.\n");
     101                return EIO;
     102        }
     103
     104        rc = fun_subtree_print(root_fun, 0);
     105        if (rc != EOK)
     106                return EIO;
     107
     108        return EOK;
     109}
     110
     111static int fun_online(const char *path)
     112{
     113        devman_handle_t funh;
     114        int rc;
     115
     116        rc = devman_fun_get_handle(path, &funh, 0);
     117        if (rc != EOK) {
     118                printf(NAME ": Error resolving device function '%s' (%s)\n",
     119                    path, str_error(rc));
     120                return rc;
     121        }
     122
     123        rc = devman_fun_online(funh);
     124        if (rc != EOK) {
     125                printf(NAME ": Failed to online function '%s'.\n", path);
     126                return rc;
     127        }
     128
     129        return EOK;
     130}
     131
     132static int fun_offline(const char *path)
     133{
     134        devman_handle_t funh;
     135        int rc;
     136
     137        rc = devman_fun_get_handle(path, &funh, 0);
     138        if (rc != EOK) {
     139                printf(NAME ": Error resolving device function '%s' (%s)\n",
     140                    path, str_error(rc));
     141                return rc;
     142        }
     143
     144        rc = devman_fun_offline(funh);
     145        if (rc != EOK) {
     146                printf(NAME ": Failed to offline function '%s'.\n", path);
     147                return rc;
     148        }
     149
     150        return EOK;
     151}
     152
     153static void print_syntax(void)
     154{
     155        printf("syntax: devctl [(online|offline) <function>]\n");
     156}
     157
     158int main(int argc, char *argv[])
     159{
     160        int rc;
     161
     162        if (argc == 1) {
     163                rc = fun_tree_print();
     164                if (rc != EOK)
     165                        return 2;
     166        } else if (str_cmp(argv[1], "online") == 0) {
     167                if (argc < 3) {
     168                        printf(NAME ": Argument missing.\n");
     169                        print_syntax();
     170                        return 1;
     171                }
     172
     173                rc = fun_online(argv[2]);
     174                if (rc != EOK) {
     175                        return 2;
     176                }
     177        } else if (str_cmp(argv[1], "offline") == 0) {
     178                if (argc < 3) {
     179                        printf(NAME ": Argument missing.\n");
     180                        print_syntax();
     181                        return 1;
     182                }
     183
     184                rc = fun_offline(argv[2]);
     185                if (rc != EOK) {
     186                        return 2;
     187                }
     188        } else {
     189                printf(NAME ": Invalid argument '%s'.\n", argv[1]);
     190                print_syntax();
    100191                return 1;
    101192        }
    102 
    103         rc = fun_tree_print(root_fun, 0);
    104         if (rc != EOK)
    105                 return 1;
    106193
    107194        return 0;
  • uspace/app/init/init.c

    rbd5f3b7 r00aece0  
    121121       
    122122        int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
    123             IPC_FLAG_BLOCKING);
     123            IPC_FLAG_BLOCKING, 0);
    124124        return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
    125125            ROOT_DEVICE, rc);
     
    138138{
    139139        int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
    140             IPC_FLAG_BLOCKING);
     140            IPC_FLAG_BLOCKING, 0);
    141141        return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
    142142            LOCFS_FS_TYPE, NULL, rc);
     
    196196}
    197197
    198 static void console(const char *svc)
    199 {
    200         printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, svc);
     198static void console(const char *isvc, const char *fbsvc)
     199{
     200        printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
    201201       
    202202        /* Wait for the input service to be ready */
    203203        service_id_t service_id;
    204         int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
    205         if (rc != EOK) {
    206                 printf("%s: Error waiting on %s (%s)\n", NAME, svc,
    207                     str_error(rc));
    208                 return;
    209         }
    210        
    211         rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, svc, NULL);
    212         if (rc != EOK) {
    213                 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
    214                     svc, str_error(rc));
     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));
    215223        }
    216224}
     
    253261static bool mount_tmpfs(void)
    254262{
    255         int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0);
     263        int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
    256264        return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
    257265            TMPFS_FS_TYPE, NULL, rc);
     
    260268static bool mount_data(void)
    261269{
    262         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);
    263271        return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
    264272            DATA_DEVICE, rc);
     
    294302        spawn("/srv/obio");
    295303        srv_start("/srv/cuda_adb");
    296         srv_start("/srv/i8042");
    297304        srv_start("/srv/s3c24ser");
    298305        srv_start("/srv/s3c24ts");
    299306       
     307        spawn("/srv/net");
     308       
    300309        spawn("/srv/fb");
    301310        spawn("/srv/input");
    302         console("hid/input");
     311        console("hid/input", "hid/fb0");
    303312       
    304313        spawn("/srv/clip");
     314        spawn("/srv/remcons");
    305315       
    306316        /*
  • uspace/app/klog/klog.c

    rbd5f3b7 r00aece0  
    205205        klog_length = size / sizeof(wchar_t);
    206206       
    207         klog = (wchar_t *) as_get_mappable_page(size);
    208         if (klog == NULL) {
    209                 fprintf(stderr, "%s: Unable to allocate virtual memory area\n",
    210                     NAME);
    211                 return ENOMEM;
    212         }
    213        
    214         rc = physmem_map((void *) faddr, (void *) klog, pages,
    215             AS_AREA_READ | AS_AREA_CACHEABLE);
     207        rc = physmem_map((void *) faddr, pages,
     208            AS_AREA_READ | AS_AREA_CACHEABLE, (void *) &klog);
    216209        if (rc != EOK) {
    217210                fprintf(stderr, "%s: Unable to map klog\n", NAME);
  • uspace/app/locinfo/locinfo.c

    rbd5f3b7 r00aece0  
    8989                        }
    9090                        printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]);
     91                        free(svc_name);
    9192                }
    9293
  • uspace/app/mkbd/main.c

    rbd5f3b7 r00aece0  
    4848#include <usb/dev/pipes.h>
    4949#include <async.h>
     50#include <usb/dev.h>
    5051#include <usb/hid/usages/core.h>
    5152#include <usb/hid/hidparser.h>
     
    6970        int rc = usb_hid_report_init(*report);
    7071        if (rc != EOK) {
    71                 usb_hid_free_report(*report);
     72                usb_hid_report_deinit(*report);
    7273                *report = NULL;
    7374                return rc;
     
    7980            &report_desc_size);
    8081        if (rc != EOK) {
    81                 usb_hid_free_report(*report);
     82                usb_hid_report_deinit(*report);
    8283                *report = NULL;
    8384                return rc;
     
    8586       
    8687        if (report_desc_size == 0) {
    87                 usb_hid_free_report(*report);
     88                usb_hid_report_deinit(*report);
    8889                *report = NULL;
    8990                // TODO: other error code?
     
    9394        uint8_t *desc = (uint8_t *) malloc(report_desc_size);
    9495        if (desc == NULL) {
    95                 usb_hid_free_report(*report);
     96                usb_hid_report_deinit(*report);
    9697                *report = NULL;
    9798                return ENOMEM;
     
    103104            &actual_size);
    104105        if (rc != EOK) {
    105                 usb_hid_free_report(*report);
     106                usb_hid_report_deinit(*report);
    106107                *report = NULL;
    107108                free(desc);
     
    110111       
    111112        if (actual_size != report_desc_size) {
    112                 usb_hid_free_report(*report);
     113                usb_hid_report_deinit(*report);
    113114                *report = NULL;
    114115                free(desc);
  • uspace/app/mkfat/fat.h

    rbd5f3b7 r00aece0  
    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

    rbd5f3b7 r00aece0  
    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
     
    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     service_id_t service_id);
    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
     
    9693        char *dev_path;
    9794        service_id_t service_id;
    98         size_t block_size;
    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;
     156        printf("Device: %s\n", dev_path);
    139157
    140158        rc = loc_service_get_id(dev_path, &service_id, 0);
     
    150168        }
    151169
    152         rc = block_get_bsize(service_id, &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");
     
    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, service_id);
     204        rc = fat_blocks_write(&cfg, service_id);
    186205        if (rc != EOK) {
    187206                printf(NAME ": Error writing device.\n");
     
    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, service_id_t service_id)
     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);
     272        fat_bootsec_create(cfg, &bs);
    246273
    247274        rc = block_write_direct(service_id, BS_BLOCK, 1, &bs);
     
    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) {
     286        for (i = 0; i < cfg->reserved_sectors - 1; ++i) {
    259287                rc = block_write_direct(service_id, addr, 1, buffer);
    260288                if (rc != EOK)
     
    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
     
    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(service_id, 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

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

    rbd5f3b7 r00aece0  
    241241                /* Accept a socket if a stream socket is used */
    242242                addrlen = sizeof(address_buf);
     243                if (verbose)
     244                        printf("accept()\n");
    243245                socket_id = accept(listening_id, (void *) address_buf, &addrlen);
    244246                if (socket_id <= 0) {
     
    258260
    259261                /* Receive a message to echo */
     262                if (verbose)
     263                        printf("recvfrom()\n");
    260264                rcv_size = recvfrom(socket_id, data, size, 0, address,
    261265                    &addrlen);
     
    297301
    298302                        /* Answer the request either with the static reply or the original data */
    299                         rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen);
    300                         if (rc != EOK)
    301                                 socket_print_error(stderr, rc, "Socket send: ", "\n");
     303                        if (type == SOCK_STREAM) {
     304                                if (verbose)
     305                                        printf("send()\n");
     306                                rc = send(socket_id, reply ? reply : data, reply ? reply_length : length, 0);
     307                                if (rc != EOK)
     308                                        socket_print_error(stderr, rc, "Socket send: ", "\n");
     309                        } else {
     310                                if (verbose)
     311                                        printf("sendto()\n");
     312                                rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen);
     313                                if (rc != EOK)
     314                                        socket_print_error(stderr, rc, "Socket send: ", "\n");
     315                        }
    302316                }
    303317
  • uspace/app/pcc/cc/cc/Makefile

    rbd5f3b7 r00aece0  
    11#
    2 # Copyright (c) 2011 Vojtech Horky
     2# Copyright (c) 2011 Jiri Zarevucky
    33# All rights reserved.
    44#
     
    2828
    2929USPACE_PREFIX = ../../../..
     30MIPDIR = ../../mip
     31ARCHDIR = ../../arch/$(PLATFORM)
     32OSDIR = ../../os/helenos
     33EXTRA_CFLAGS = -I$(MIPDIR) -I$(ARCHDIR) -I$(OSDIR) -w
     34DEFS = -Dmach_$(PLATFORM) -D__helenos__
     35BINARY = cc
    3036
    31 LIBS = \
    32         $(LIBUSBHID_PREFIX)/libusbhid.a \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
     37PRE_DEPEND = compat.c
     38EXTRA_CLEAN = compat.c
    3639
    37 EXTRA_CFLAGS += \
    38         -I$(LIBUSB_PREFIX)/include \
    39         -I$(LIBUSBDEV_PREFIX)/include \
    40         -I$(LIBUSBHID_PREFIX)/include \
    41         -I$(LIBDRV_PREFIX)/include
    42 
    43 BINARY = usbmouse
     40POSIX_COMPAT = y
    4441
    4542SOURCES = \
    46         init.c \
    47         main.c \
    48         mouse.c
     43        cc.c \
     44        compat.c
    4945
    5046include $(USPACE_PREFIX)/Makefile.common
     47
     48compat.c: $(MIPDIR)/compat.c
     49        ln -s -f $^ $@
     50
  • uspace/app/sysinfo/sysinfo.c

    rbd5f3b7 r00aece0  
    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/tester/console/console1.c

    rbd5f3b7 r00aece0  
    7676                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    7777                                console_flush(console);
    78                                 console_set_color(console, i, COLOR_WHITE,
     78                                console_set_color(console, COLOR_WHITE, i,
    7979                                    j ? CATTR_BRIGHT : 0);
    8080                                printf(" %s ", color_name[i]);
     
    8989                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    9090                                console_flush(console);
    91                                 console_set_color(console, COLOR_WHITE, i,
     91                                console_set_color(console, i, COLOR_WHITE,
    9292                                    j ? CATTR_BRIGHT : 0);
    9393                                printf(" %s ", color_name[i]);
     
    102102                for (i = 0; i < 255; i += 16) {
    103103                        console_flush(console);
    104                         console_set_rgb_color(console, (255 - i) << 16, i << 16);
     104                        console_set_rgb_color(console, i << 16, (255 - i) << 16);
    105105                        putchar('X');
    106106                }
    107107                console_flush(console);
    108                 console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0);
     108                console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0);
    109109                putchar('\n');
    110110               
    111111                for (i = 0; i < 255; i += 16) {
    112112                        console_flush(console);
    113                         console_set_rgb_color(console, (255 - i) << 8, i << 8);
     113                        console_set_rgb_color(console, i << 8, (255 - i) << 8);
    114114                        putchar('X');
    115115                }
    116116                console_flush(console);
    117                 console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0);
     117                console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0);
    118118                putchar('\n');
    119119               
    120120                for (i = 0; i < 255; i += 16) {
    121121                        console_flush(console);
    122                         console_set_rgb_color(console, 255 - i, i);
     122                        console_set_rgb_color(console, i, 255 - i);
    123123                        putchar('X');
    124124                }
  • uspace/app/tester/mm/common.c

    rbd5f3b7 r00aece0  
    342342        link_initialize(&area->link);
    343343       
    344         /* Map the memory area */
    345         void *addr = as_get_mappable_page(size);
    346         if (addr == NULL) {
     344        area->addr = as_area_create((void *) -1, size,
     345            AS_AREA_WRITE | AS_AREA_READ);
     346        if (area->addr == (void *) -1) {
    347347                free(area);
    348348                check_consistency("map_area (a)");
    349                 return NULL;
    350         }
    351        
    352         area->addr = as_area_create(addr, size, AS_AREA_WRITE | AS_AREA_READ);
    353         if (area->addr == (void *) -1) {
    354                 free(area);
    355                 check_consistency("map_area (b)");
    356349                return NULL;
    357350        }
  • uspace/app/tester/mm/mapping1.c

    rbd5f3b7 r00aece0  
    3535#include "../tester.h"
    3636
    37 #define BUFFER1_PAGES 4
    38 #define BUFFER2_PAGES 2
     37#define BUFFER1_PAGES  4
     38#define BUFFER2_PAGES  2
    3939
    4040static void *create_as_area(size_t size)
    4141{
    42         void *result = as_get_mappable_page(size);
    4342        TPRINTF("Creating AS area...\n");
    44         if (as_area_create(result, size,
    45             AS_AREA_READ | AS_AREA_WRITE) != result) {
     43       
     44        void *result = as_area_create((void *) -1, size,
     45            AS_AREA_READ | AS_AREA_WRITE);
     46        if (result == (void *) -1)
    4647                return NULL;
    47         }
     48       
    4849        return result;
    4950}
     
    7172        int i;
    7273        for (i = 0; i < page_count; i++) {
    73                 void *page_start = ((char *)area) + PAGE_SIZE * i;
     74                void *page_start = ((char *) area) + PAGE_SIZE * i;
    7475                int rc = as_get_physical_mapping(page_start, NULL);
    7576                if (rc != expected_rc) {
  • uspace/app/tester/print/print2.c

    rbd5f3b7 r00aece0  
    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/tetris/screen.c

    rbd5f3b7 r00aece0  
    9595{
    9696        console_flush(console);
    97         console_set_rgb_color(console, 0xffffff,
    98             use_color ? color : 0x000000);
     97        console_set_rgb_color(console, use_color ? color : 0x000000,
     98            0xffffff);
    9999}
    100100
     
    153153                return false;
    154154       
    155         return (ccap >= CONSOLE_CCAP_RGB);
     155        return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
    156156}
    157157
  • uspace/app/tetris/shapes.c

    rbd5f3b7 r00aece0  
    6969
    7070const struct shape shapes[] = {
    71         /*  0 */  {  7,  7, { TL, TC, MR }, 0xff042d},
    72         /*  1 */  {  8,  8, { TC, TR, ML }, 0xff9304},
    73         /*  2 */  {  9, 11, { ML, MR, BC }, 0xbeff04},
    74         /*  3 */  {  3,  3, { TL, TC, ML }, 0x63ff04},
    75         /*  4 */  { 12, 14, { ML, BL, MR }, 0xce04ff},
    76         /*  5 */  { 15, 17, { ML, BR, MR }, 0xff04cf},
    77         /*  6 */  { 18, 18, { ML, MR, 2  }, 0x7604ff},  /* sticks out */
    78         /*  7 */  {  0,  0, { TC, ML, BL }, 0xff042d},
    79         /*  8 */  {  1,  1, { TC, MR, BR }, 0xff9304},
    80         /*  9 */  { 10,  2, { TC, MR, BC }, 0xbeff04},
    81         /* 10 */  { 11,  9, { TC, ML, MR }, 0xbeff04},
    82         /* 11 */  {  2, 10, { TC, ML, BC }, 0xbeff04},
    83         /* 12 */  { 13,  4, { TC, BC, BR }, 0xce04ff},
    84         /* 13 */  { 14, 12, { TR, ML, MR }, 0xce04ff},
    85         /* 14 */  {  4, 13, { TL, TC, BC }, 0xce04ff},
    86         /* 15 */  { 16,  5, { TR, TC, BC }, 0xff04cf},
    87         /* 16 */  { 17, 15, { TL, MR, ML }, 0xff04cf},
    88         /* 17 */  {  5, 16, { TC, BC, BL }, 0xff04cf},
    89         /* 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 */
    9090};
    9191
  • uspace/app/tetris/tetris.c

    rbd5f3b7 r00aece0  
    291291                for (j = i + 1; j <= 5; j++) {
    292292                        if (keys[i] == keys[j])
    293                                 errx(1, "duplicate command keys specified.");
     293                                errx(1, "%s", "duplicate command keys specified.");
    294294                }
    295295               
  • uspace/app/trace/syscalls.c

    rbd5f3b7 r00aece0  
    7272    [SYS_PHYSMEM_MAP] = { "physmem_map",                4,      V_ERRNO },
    7373    [SYS_IOSPACE_ENABLE] = { "iospace_enable",          1,      V_ERRNO },
    74     [SYS_REGISTER_IRQ] = { "register_irq",      4,      V_ERRNO },
    75     [SYS_UNREGISTER_IRQ] = { "unregister_irq",  2,      V_ERRNO },
     74    [SYS_IRQ_REGISTER] = { "irq_register",      4,      V_ERRNO },
     75    [SYS_IRQ_UNREGISTER] = { "irq_unregister",  2,      V_ERRNO },
    7676
    77     [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",                2,      V_INTEGER },
     77    [SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type",              2,      V_INTEGER },
    7878    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",            3,      V_ERRNO },
    7979    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",    3,      V_ERRNO },
  • uspace/app/trace/trace.c

    rbd5f3b7 r00aece0  
    8686void thread_trace_start(uintptr_t thread_hash);
    8787
    88 static proto_t *proto_console;
    8988static task_id_t task_id;
    9089static loader_t *task_ldr;
     
    624623error:
    625624        loader_abort(ldr);
    626         free(ldr);
    627625        return NULL;
    628626}
     
    659657        ipcp_init();
    660658
    661         /*
    662          * User apps now typically have console on phone 3.
    663          * (Phones 1 and 2 are used by the loader).
    664          */
    665         ipcp_connection_set(3, 0, proto_console);
    666 
    667659        rc = get_thread_list();
    668660        if (rc < 0) {
     
    714706                        fibril_mutex_unlock(&state_lock);
    715707                        printf("Resume...\n");
     708                        break;
     709                default:
    716710                        break;
    717711                }
     
    790784
    791785        proto_register(SERVICE_VFS, p);
    792 
    793 #if 0
    794         p = proto_new("console");
    795 
    796         o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
    797         proto_add_oper(p, VFS_IN_WRITE, o);
    798 
    799         resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
    800         resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR;
    801         o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def);
    802 
    803         arg_def[0] = V_CHAR;
    804         o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def);
    805         proto_add_oper(p, CONSOLE_CLEAR, o);
    806 
    807         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
    808         o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def);
    809         proto_add_oper(p, CONSOLE_GOTO, o);
    810 
    811         resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
    812         o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def);
    813         proto_add_oper(p, CONSOLE_GET_SIZE, o);
    814 
    815         arg_def[0] = V_INTEGER;
    816         o = oper_new("set_style", 1, arg_def, V_VOID, 0, resp_def);
    817         proto_add_oper(p, CONSOLE_SET_STYLE, o);
    818         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER;
    819         o = oper_new("set_color", 3, arg_def, V_VOID, 0, resp_def);
    820         proto_add_oper(p, CONSOLE_SET_COLOR, o);
    821         arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
    822         o = oper_new("set_rgb_color", 2, arg_def, V_VOID, 0, resp_def);
    823         proto_add_oper(p, CONSOLE_SET_RGB_COLOR, o);
    824         o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def);
    825         proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);
    826 
    827         proto_console = p;
    828         proto_register(SERVICE_CONSOLE, p);
    829 #endif
    830786}
    831787
  • uspace/app/usbinfo/desctree.c

    rbd5f3b7 r00aece0  
    5050
    5151static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
    52     usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
     52    usb_dp_parser_data_t *data, const uint8_t *root, size_t depth,
    5353    dump_descriptor_in_tree_t callback, void *arg)
    5454{
     
    5757        }
    5858        callback(root, depth, arg);
    59         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     59        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    6060        do {
    6161                browse_descriptor_tree_internal(parser, data, child, depth + 1,
  • uspace/app/usbinfo/dev.c

    rbd5f3b7 r00aece0  
    3434 * Representation of queried device.
    3535 */
    36 #include <usb/dev/pipes.h>
     36#include <usb/dev.h>
     37#include <usb/hc.h>
    3738#include <errno.h>
    3839#include <str_error.h>
     
    5253        bool transfer_started = false;
    5354
    54         rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr);
     55        usb_hc_connection_initialize(&dev->hc_conn, hc_handle);
     56
     57        rc = usb_device_connection_initialize(
     58            &dev->wire, &dev->hc_conn, dev_addr);
    5559        if (rc != EOK) {
    5660                fprintf(stderr,
  • uspace/app/usbinfo/dump.c

    rbd5f3b7 r00aece0  
    110110}
    111111
    112 static void dump_tree_descriptor(uint8_t *descriptor, size_t depth)
     112static void dump_tree_descriptor(const uint8_t *descriptor, size_t depth)
    113113{
    114114        if (descriptor == NULL) {
    115115                return;
    116116        }
    117         int type = (int) *(descriptor + 1);
     117        int type = descriptor[1];
    118118        const char *name = "unknown";
    119119        switch (type) {
     
    136136}
    137137
    138 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
    139     uint8_t *root, size_t depth)
     138static void dump_tree_internal(
     139    usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     140    const uint8_t *root, size_t depth)
    140141{
    141142        if (root == NULL) {
     
    143144        }
    144145        dump_tree_descriptor(root, depth);
    145         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     146        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    146147        do {
    147148                dump_tree_internal(parser, data, child, depth + 1);
     
    152153static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
    153154{
    154         uint8_t *ptr = data->data;
     155        const uint8_t *ptr = data->data;
    155156        printf("Descriptor tree:\n");
    156157        dump_tree_internal(parser, data, ptr, 0);
  • uspace/app/usbinfo/hid.c

    rbd5f3b7 r00aece0  
    5555} descriptor_walk_context_t;
    5656
    57 static bool is_descriptor_kind(uint8_t *d, usb_descriptor_type_t t)
     57static bool is_descriptor_kind(const uint8_t *d, usb_descriptor_type_t t)
    5858{
    5959        if (d == NULL) {
     
    167167
    168168        free(raw_report);
    169         usb_hid_free_report(&report);
     169        usb_hid_report_deinit(&report);
    170170}
    171171
     
    180180 * @param arg Custom argument, passed as descriptor_walk_context_t.
    181181 */
    182 static void descriptor_walk_callback(uint8_t *raw_descriptor,
     182static void descriptor_walk_callback(const uint8_t *raw_descriptor,
    183183    size_t depth, void *arg)
    184184{
  • uspace/app/usbinfo/info.c

    rbd5f3b7 r00aece0  
    5151}
    5252
    53 static void dump_match_ids_from_interface(uint8_t *descriptor, size_t depth,
    54     void *arg)
     53static void dump_match_ids_from_interface(
     54    const uint8_t *descriptor, size_t depth, void *arg)
    5555{
    5656        if (depth != 1) {
     
    165165
    166166
    167 static void dump_descriptor_tree_callback(uint8_t *descriptor,
    168     size_t depth, void *arg)
     167static void dump_descriptor_tree_callback(
     168    const uint8_t *descriptor, size_t depth, void *arg)
    169169{
    170170        const char *indent = get_indent(depth + 1);
     
    246246}
    247247
    248 static void find_string_indexes_callback(uint8_t *descriptor,
    249     size_t depth, void *arg)
     248static void find_string_indexes_callback(
     249    const uint8_t *descriptor, size_t depth, void *arg)
    250250{
    251251        size_t descriptor_length = descriptor[0];
     
    287287void dump_strings(usbinfo_device_t *dev)
    288288{
     289        /* Find used indexes. Devices with more than 64 strings are very rare.*/
     290        uint64_t str_mask = 0;
     291        find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,
     292            &str_mask);
     293        usb_dp_walk_simple(dev->full_configuration_descriptor,
     294            dev->full_configuration_descriptor_size,
     295            usb_dp_standard_descriptor_nesting,
     296            find_string_indexes_callback,
     297            &str_mask);
     298
     299        if (str_mask == 0) {
     300                printf("Device does not support string descriptors.\n");
     301                return;
     302        }
     303
    289304        /* Get supported languages. */
    290305        l18_win_locales_t *langs;
     
    305320        }
    306321        printf(".\n");
    307 
    308         /* Find used indexes. Device with more than 64 strings are very rare.
    309          */
    310         uint64_t str_mask = 0;
    311         find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,
    312             &str_mask);
    313         usb_dp_walk_simple(dev->full_configuration_descriptor,
    314             dev->full_configuration_descriptor_size,
    315             usb_dp_standard_descriptor_nesting,
    316             find_string_indexes_callback,
    317             &str_mask);
    318322
    319323        /* Get all strings and dump them. */
  • uspace/app/usbinfo/main.c

    rbd5f3b7 r00aece0  
    4444#include <loc.h>
    4545#include <usb/hc.h>
     46#include <usb/dev.h>
    4647#include <usb/dev/pipes.h>
    4748#include "usbinfo.h"
  • uspace/app/usbinfo/usbinfo.h

    rbd5f3b7 r00aece0  
    4444
    4545typedef struct {
     46        usb_hc_connection_t hc_conn;
     47        usb_device_connection_t wire;
    4648        usb_pipe_t ctrl_pipe;
    47         usb_device_connection_t wire;
    4849        usb_standard_device_descriptor_t device_descriptor;
    4950        uint8_t *full_configuration_descriptor;
     
    7475void destroy_device(usbinfo_device_t *);
    7576
    76 typedef void (*dump_descriptor_in_tree_t)(uint8_t *, size_t, void *);
     77typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
    7778void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
    7879    dump_descriptor_in_tree_t, size_t, void *);
  • uspace/app/vuhid/Makefile

    rbd5f3b7 r00aece0  
    4747
    4848SOURCES_INTERFACES = \
    49         hids/bootkbd.c
     49        hids/bootkbd.c \
     50        hids/logitech_wireless.c
    5051
    5152SOURCES = \
     
    5354        device.c \
    5455        ifaces.c \
     56        life.c \
    5557        stdreq.c \
    5658        $(SOURCES_INTERFACES)
  • uspace/app/vuhid/hids/bootkbd.c

    rbd5f3b7 r00aece0  
    9393             0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    9494};
    95 static size_t in_data_count = sizeof(in_data)/INPUT_SIZE;
    96 // FIXME - locking
    97 static size_t in_data_position = 0;
    98 
    99 static int on_data_in(vuhid_interface_t *iface,
    100     void *buffer, size_t buffer_size, size_t *act_buffer_size)
    101 {
    102         static size_t last_pos = (size_t) -1;
    103         size_t pos = in_data_position;
    104         if (pos >= in_data_count) {
    105                 return EBADCHECKSUM;
    106         }
    107 
    108         if (last_pos == pos) {
    109                 return ENAK;
    110         }
    111 
    112         if (buffer_size > INPUT_SIZE) {
    113                 buffer_size = INPUT_SIZE;
    114         }
    115 
    116         if (act_buffer_size != NULL) {
    117                 *act_buffer_size = buffer_size;
    118         }
    119 
    120         memcpy(buffer, in_data + pos * INPUT_SIZE, buffer_size);
    121         last_pos = pos;
    122 
    123         return EOK;
    124 }
     95static vuhid_interface_life_t boot_life = {
     96        .data_in = in_data,
     97        .data_in_count = sizeof(in_data)/INPUT_SIZE,
     98        .data_in_pos_change_delay = 500,
     99        .msg_born = "Boot keyboard comes to life...",
     100        .msg_die = "Boot keyboard died."
     101};
    125102
    126103static int on_data_out(vuhid_interface_t *iface,
     
    141118}
    142119
    143 
    144 static void live(vuhid_interface_t *iface)
    145 {
    146         async_usleep(1000 * 1000 * 5);
    147         usb_log_debug("Boot keyboard comes to life...\n");
    148         while (in_data_position < in_data_count) {
    149                 async_usleep(1000 * 500);
    150                 in_data_position++;
    151         }
    152         usb_log_debug("Boot keyboard died.\n");
    153 }
    154 
    155 
    156120vuhid_interface_t vuhid_interface_bootkbd = {
    157121        .id = "boot",
     
    164128
    165129        .in_data_size = INPUT_SIZE,
    166         .on_data_in = on_data_in,
     130        .on_data_in = interface_live_on_data_in,
    167131
    168132        .out_data_size = 1,
    169133        .on_data_out = on_data_out,
    170134
    171         .live = live,
     135        .live = interface_life_live,
    172136
     137        .interface_data = &boot_life,
    173138        .vuhid_data = NULL
    174139};
  • uspace/app/vuhid/ifaces.c

    rbd5f3b7 r00aece0  
    3838
    3939extern vuhid_interface_t vuhid_interface_bootkbd;
     40extern vuhid_interface_t vuhid_interface_logitech_wireless_1;
    4041
    4142vuhid_interface_t *available_hid_interfaces[] = {
    4243        &vuhid_interface_bootkbd,
     44        &vuhid_interface_logitech_wireless_1,
    4345        NULL
    4446};
  • uspace/app/vuhid/life.c

    rbd5f3b7 r00aece0  
    2727 */
    2828
    29 /** @addtogroup drvusbmouse
     29/** @addtogroup usbvirthid
    3030 * @{
    3131 */
    3232/**
    3333 * @file
    34  * Common definitions for USB mouse driver.
     34 *
    3535 */
     36#include <errno.h>
     37#include <usb/debug.h>
     38#include "virthid.h"
    3639
    37 #ifndef USBMOUSE_MOUSE_H_
    38 #define USBMOUSE_MOUSE_H_
    3940
    40 #include <usb/dev/driver.h>
    41 #include <usb/dev/pipes.h>
    42 #include <time.h>
    43 #include <async.h>
     41void interface_life_live(vuhid_interface_t *iface)
     42{
     43        vuhid_interface_life_t *data = iface->interface_data;
     44        data->data_in_pos = 0;
     45        data->data_in_last_pos = (size_t) -1;
     46        async_usleep(1000 * 1000 * 5);
     47        usb_log_debug("%s\n", data->msg_born);
     48        while (data->data_in_pos < data->data_in_count) {
     49                async_usleep(1000 * data->data_in_pos_change_delay);
     50                // FIXME: proper locking
     51                data->data_in_pos++;
     52        }
     53        usb_log_debug("%s\n", data->msg_die);
     54}
    4455
    45 #define POLL_PIPE(dev) \
    46         ((dev)->pipes[0].pipe)
    4756
    48 /** Container for USB mouse device. */
    49 typedef struct {
    50         /** Generic device container. */
    51         usb_device_t *dev;
    52        
    53         /** Function representing the device. */
    54         ddf_fun_t *mouse_fun;
    55        
    56         /** Polling interval in microseconds. */
    57         suseconds_t poll_interval_us;
    58        
    59         /** Callback session to console (consumer). */
    60         async_sess_t *console_sess;
    61 } usb_mouse_t;
    6257
    63 extern usb_endpoint_description_t poll_endpoint_description;
     58int interface_live_on_data_in(vuhid_interface_t *iface,
     59    void *buffer, size_t buffer_size, size_t *act_buffer_size)
     60{
     61        vuhid_interface_life_t *life = iface->interface_data;
     62        size_t pos = life->data_in_pos;
     63        if (pos >= life->data_in_count) {
     64                return EBADCHECKSUM;
     65        }
    6466
    65 extern int usb_mouse_create(usb_device_t *);
    66 extern bool usb_mouse_polling_callback(usb_device_t *, uint8_t *, size_t,
    67     void *);
    68 extern void usb_mouse_polling_ended_callback(usb_device_t *, bool, void *);
     67        if (pos == life->data_in_last_pos) {
     68                return ENAK;
     69        }
    6970
    70 #endif
     71        if (buffer_size > iface->in_data_size) {
     72                buffer_size = iface->in_data_size;
     73        }
    7174
    72 /**
    73  * @}
     75        if (act_buffer_size != NULL) {
     76                *act_buffer_size = buffer_size;
     77        }
     78
     79        memcpy(buffer, life->data_in + pos * iface->in_data_size, buffer_size);
     80        life->data_in_last_pos = pos;
     81
     82        return EOK;
     83}
     84
     85/** @}
    7486 */
  • uspace/app/vuhid/virthid.h

    rbd5f3b7 r00aece0  
    8282
    8383typedef struct {
     84        /** Buffer with data from device to the host. */
     85        uint8_t *data_in;
     86        /** Number of items in @c data_in.
     87         * The total size of @c data_in buffer shall be
     88         * <code>data_in_count * vuhid_interface_t.in_data_size</code>.
     89         */
     90        size_t data_in_count;
     91
     92        /** Current position in the data buffer. */
     93        size_t data_in_pos;
     94        /** Previous position. */
     95        size_t data_in_last_pos;
     96
     97        /** Delay between transition to "next" input buffer (in ms). */
     98        size_t data_in_pos_change_delay;
     99
     100        /** Message to print when interface becomes alive. */
     101        const char *msg_born;
     102        /** Message to print when interface dies. */
     103        const char *msg_die;
     104} vuhid_interface_life_t;
     105
     106typedef struct {
    84107        uint8_t length;
    85108        uint8_t type;
     
    94117void wait_for_interfaces_death(usbvirt_device_t *);
    95118
     119void interface_life_live(vuhid_interface_t *);
     120int interface_live_on_data_in(vuhid_interface_t *, void *, size_t, size_t *);
     121
     122
    96123#endif
    97124/**
  • uspace/app/websrv/websrv.c

    rbd5f3b7 r00aece0  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/**
    33  * @file (Less-than-skeleton) web server.
     33 * @file Skeletal web server.
    3434 */
    3535
     36#include <bool.h>
     37#include <errno.h>
    3638#include <stdio.h>
     39#include <sys/types.h>
     40#include <sys/stat.h>
     41#include <stdlib.h>
     42#include <fcntl.h>
    3743
    3844#include <net/in.h>
     
    4046#include <net/socket.h>
    4147
     48#include <arg_parse.h>
     49#include <macros.h>
    4250#include <str.h>
    43 
    44 #define PORT_NUMBER 8080
     51#include <str_error.h>
     52
     53#define NAME  "websrv"
     54
     55#define DEFAULT_PORT  8080
     56#define BACKLOG_SIZE  3
     57
     58#define WEB_ROOT  "/data/web"
    4559
    4660/** Buffer for receiving the request. */
    47 #define BUFFER_SIZE 1024
    48 static char buf[BUFFER_SIZE];
    49 
    50 /** Response to send to client. */
    51 static const char *response_msg =
     61#define BUFFER_SIZE  1024
     62
     63static uint16_t port = DEFAULT_PORT;
     64
     65static char rbuf[BUFFER_SIZE];
     66static size_t rbuf_out;
     67static size_t rbuf_in;
     68
     69static char lbuf[BUFFER_SIZE + 1];
     70static size_t lbuf_used;
     71
     72static char fbuf[BUFFER_SIZE];
     73
     74/** Responses to send to client. */
     75
     76static const char *msg_ok =
    5277    "HTTP/1.0 200 OK\r\n"
     78    "\r\n";
     79
     80static const char *msg_bad_request =
     81    "HTTP/1.0 400 Bad Request\r\n"
    5382    "\r\n"
    54     "<h1>Hello from HelenOS!</h1>\r\n";
     83    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
     84    "<html><head>\r\n"
     85    "<title>400 Bad Request</title>\r\n"
     86    "</head>\r\n"
     87    "<body>\r\n"
     88    "<h1>Bad Request</h1>\r\n"
     89    "<p>The requested URL has bad syntax.</p>\r\n"
     90    "</body>\r\n"
     91    "</html>\r\n";
     92
     93static const char *msg_not_found =
     94    "HTTP/1.0 404 Not Found\r\n"
     95    "\r\n"
     96    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
     97    "<html><head>\r\n"
     98    "<title>404 Not Found</title>\r\n"
     99    "</head>\r\n"
     100    "<body>\r\n"
     101    "<h1>Not Found</h1>\r\n"
     102    "<p>The requested URL was not found on this server.</p>\r\n"
     103    "</body>\r\n"
     104    "</html>\r\n";
     105
     106static const char *msg_not_implemented =
     107    "HTTP/1.0 501 Not Implemented\r\n"
     108    "\r\n"
     109    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
     110    "<html><head>\r\n"
     111    "<title>501 Not Implemented</title>\r\n"
     112    "</head>\r\n"
     113    "<body>\r\n"
     114    "<h1>Not Implemented</h1>\r\n"
     115    "<p>The requested method is not implemented on this server.</p>\r\n"
     116    "</body>\r\n"
     117    "</html>\r\n";
     118
     119/** Receive one character (with buffering) */
     120static int recv_char(int fd, char *c)
     121{
     122        if (rbuf_out == rbuf_in) {
     123                rbuf_out = 0;
     124                rbuf_in = 0;
     125               
     126                ssize_t rc = recv(fd, rbuf, BUFFER_SIZE, 0);
     127                if (rc <= 0) {
     128                        fprintf(stderr, "recv() failed (%zd)\n", rc);
     129                        return rc;
     130                }
     131               
     132                rbuf_in = rc;
     133        }
     134       
     135        *c = rbuf[rbuf_out++];
     136        return EOK;
     137}
     138
     139/** Receive one line with length limit */
     140static int recv_line(int fd)
     141{
     142        char *bp = lbuf;
     143        char c = '\0';
     144       
     145        while (bp < lbuf + BUFFER_SIZE) {
     146                char prev = c;
     147                int rc = recv_char(fd, &c);
     148               
     149                if (rc != EOK)
     150                        return rc;
     151               
     152                *bp++ = c;
     153                if ((prev == '\r') && (c == '\n'))
     154                        break;
     155        }
     156       
     157        lbuf_used = bp - lbuf;
     158        *bp = '\0';
     159       
     160        if (bp == lbuf + BUFFER_SIZE)
     161                return ELIMIT;
     162       
     163        return EOK;
     164}
     165
     166static bool uri_is_valid(char *uri)
     167{
     168        if (uri[0] != '/')
     169                return false;
     170       
     171        if (uri[1] == '.')
     172                return false;
     173       
     174        char *cp = uri + 1;
     175       
     176        while (*cp != '\0') {
     177                char c = *cp++;
     178                if (c == '/')
     179                        return false;
     180        }
     181       
     182        return true;
     183}
     184
     185static int send_response(int conn_sd, const char *msg)
     186{
     187        size_t response_size = str_size(msg);
     188       
     189        fprintf(stderr, "Sending response\n");
     190        ssize_t rc = send(conn_sd, (void *) msg, response_size, 0);
     191        if (rc < 0) {
     192                fprintf(stderr, "send() failed\n");
     193                return rc;
     194        }
     195       
     196        return EOK;
     197}
     198
     199static int uri_get(const char *uri, int conn_sd)
     200{
     201        if (str_cmp(uri, "/") == 0)
     202                uri = "/index.htm";
     203       
     204        char *fname;
     205        int rc = asprintf(&fname, "%s%s", WEB_ROOT, uri);
     206        if (rc < 0)
     207                return ENOMEM;
     208       
     209        int fd = open(fname, O_RDONLY);
     210        if (fd < 0) {
     211                rc = send_response(conn_sd, msg_not_found);
     212                free(fname);
     213                return rc;
     214        }
     215       
     216        free(fname);
     217       
     218        rc = send_response(conn_sd, msg_ok);
     219        if (rc != EOK)
     220                return rc;
     221       
     222        while (true) {
     223                ssize_t nr = read(fd, fbuf, BUFFER_SIZE);
     224                if (nr == 0)
     225                        break;
     226               
     227                if (nr < 0) {
     228                        close(fd);
     229                        return EIO;
     230                }
     231               
     232                rc = send(conn_sd, fbuf, nr, 0);
     233                if (rc < 0) {
     234                        fprintf(stderr, "send() failed\n");
     235                        close(fd);
     236                        return rc;
     237                }
     238        }
     239       
     240        close(fd);
     241       
     242        return EOK;
     243}
     244
     245static int req_process(int conn_sd)
     246{
     247        int rc = recv_line(conn_sd);
     248        if (rc != EOK) {
     249                fprintf(stderr, "recv_line() failed\n");
     250                return rc;
     251        }
     252       
     253        fprintf(stderr, "Request: %s", lbuf);
     254       
     255        if (str_lcmp(lbuf, "GET ", 4) != 0) {
     256                rc = send_response(conn_sd, msg_not_implemented);
     257                return rc;
     258        }
     259       
     260        char *uri = lbuf + 4;
     261        char *end_uri = str_chr(uri, ' ');
     262        if (end_uri == NULL) {
     263                end_uri = lbuf + lbuf_used - 2;
     264                assert(*end_uri == '\r');
     265        }
     266       
     267        *end_uri = '\0';
     268        fprintf(stderr, "Requested URI: %s\n", uri);
     269       
     270        if (!uri_is_valid(uri)) {
     271                rc = send_response(conn_sd, msg_bad_request);
     272                return rc;
     273        }
     274       
     275        return uri_get(uri, conn_sd);
     276}
     277
     278static void usage(void)
     279{
     280        printf("Skeletal server\n"
     281            "\n"
     282            "Usage: " NAME " [options]\n"
     283            "\n"
     284            "Where options are:\n"
     285            "-p port_number | --port=port_number\n"
     286            "\tListening port (default " STRING(DEFAULT_PORT) ").\n"
     287            "\n"
     288            "-h | --help\n"
     289            "\tShow this application help.\n");
     290}
     291
     292static int parse_option(int argc, char *argv[], int *index)
     293{
     294        int value;
     295        int rc;
     296       
     297        switch (argv[*index][1]) {
     298        case 'h':
     299                usage();
     300                exit(0);
     301                break;
     302        case 'p':
     303                rc = arg_parse_int(argc, argv, index, &value, 0);
     304                if (rc != EOK)
     305                        return rc;
     306               
     307                port = (uint16_t) value;
     308                break;
     309        /* Long options with double dash */
     310        case '-':
     311                if (str_lcmp(argv[*index] + 2, "help", 5) == 0) {
     312                        usage();
     313                        exit(0);
     314                } else if (str_lcmp(argv[*index] + 2, "port=", 5) == 0) {
     315                        rc = arg_parse_int(argc, argv, index, &value, 7);
     316                        if (rc != EOK)
     317                                return rc;
     318                       
     319                        port = (uint16_t) value;
     320                } else {
     321                        usage();
     322                        return EINVAL;
     323                }
     324                break;
     325        default:
     326                usage();
     327                return EINVAL;
     328        }
     329       
     330        return EOK;
     331}
    55332
    56333int main(int argc, char *argv[])
    57334{
     335        /* Parse command line arguments */
     336        for (int i = 1; i < argc; i++) {
     337                if (argv[i][0] == '-') {
     338                        int rc = parse_option(argc, argv, &i);
     339                        if (rc != EOK)
     340                                return rc;
     341                } else {
     342                        usage();
     343                        return EINVAL;
     344                }
     345        }
     346       
    58347        struct sockaddr_in addr;
    59         struct sockaddr_in raddr;
    60 
    61         socklen_t raddr_len;
    62 
    63         int listen_sd, conn_sd;
    64         int rc;
    65 
    66         size_t response_size;
    67 
     348       
    68349        addr.sin_family = AF_INET;
    69         addr.sin_port = htons(PORT_NUMBER);
    70 
    71         rc = inet_pton(AF_INET, "127.0.0.1", (void *) &addr.sin_addr.s_addr);
     350        addr.sin_port = htons(port);
     351       
     352        int rc = inet_pton(AF_INET, "127.0.0.1", (void *)
     353            &addr.sin_addr.s_addr);
    72354        if (rc != EOK) {
    73                 printf("Error parsing network address.\n");
     355                fprintf(stderr, "Error parsing network address (%s)\n",
     356                    str_error(rc));
    74357                return 1;
    75358        }
    76 
    77         printf("Creating socket.\n");
    78 
    79         listen_sd = socket(PF_INET, SOCK_STREAM, 0);
     359       
     360        fprintf(stderr, "Creating socket\n");
     361       
     362        int listen_sd = socket(PF_INET, SOCK_STREAM, 0);
    80363        if (listen_sd < 0) {
    81                 printf("Error creating listening socket.\n");
    82                 return 1;
    83         }
    84 
     364                fprintf(stderr, "Error creating listening socket (%s)\n",
     365                    str_error(listen_sd));
     366                return 2;
     367        }
     368       
    85369        rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr));
    86370        if (rc != EOK) {
    87                 printf("Error binding socket.\n");
    88                 return 1;
    89         }
    90 
    91         rc = listen(listen_sd, 1);
     371                fprintf(stderr, "Error binding socket (%s)\n",
     372                    str_error(rc));
     373                return 3;
     374        }
     375       
     376        rc = listen(listen_sd, BACKLOG_SIZE);
    92377        if (rc != EOK) {
    93                 printf("Error calling listen() (%d).\n", rc);
    94                 return 1;
    95         }
    96 
    97         response_size = str_size(response_msg);
    98 
    99         printf("Listening for connections at port number %u.\n", PORT_NUMBER);
     378                fprintf(stderr, "listen() failed (%s)\n", str_error(rc));
     379                return 4;
     380        }
     381       
     382        fprintf(stderr, "Listening for connections at port %" PRIu16 "\n",
     383            port);
    100384        while (true) {
    101                 raddr_len = sizeof(raddr);
    102                 conn_sd = accept(listen_sd, (struct sockaddr *) &raddr,
     385                struct sockaddr_in raddr;
     386                socklen_t raddr_len = sizeof(raddr);
     387                int conn_sd = accept(listen_sd, (struct sockaddr *) &raddr,
    103388                    &raddr_len);
    104 
     389               
    105390                if (conn_sd < 0) {
    106                         printf("accept() failed.\n");
    107                         return 1;
    108                 }
    109 
    110                 printf("Accepted connection, sd=%d.\n", conn_sd);
    111 
    112                 printf("Wait for client request\n");
    113 
    114                 /* Really we should wait for a blank line. */
    115                 rc = recv(conn_sd, buf, BUFFER_SIZE, 0);
    116                 if (rc < 0) {
    117                         printf("recv() failed\n");
    118                         return 1;
    119                 }
    120 
    121                 /* Send a canned response. */
    122                 printf("Send response...\n");
    123                 rc = send(conn_sd, (void *) response_msg, response_size, 0);
    124                 if (rc < 0) {
    125                         printf("send() failed.\n");
    126                         return 1;
    127                 }
    128 
     391                        fprintf(stderr, "accept() failed (%s)\n", str_error(rc));
     392                        continue;
     393                }
     394               
     395                fprintf(stderr, "Connection accepted (sd=%d), "
     396                    "waiting for request\n", conn_sd);
     397               
     398                rbuf_out = 0;
     399                rbuf_in = 0;
     400               
     401                rc = req_process(conn_sd);
     402                if (rc != EOK)
     403                        fprintf(stderr, "Error processing request (%s)\n",
     404                            str_error(rc));
     405               
    129406                rc = closesocket(conn_sd);
    130407                if (rc != EOK) {
    131                         printf("Error closing connection socket: %d\n", rc);
    132                         return 1;
    133                 }
    134 
    135                 printf("Closed connection.\n");
    136         }
    137 
    138         /* Not reached. */
     408                        fprintf(stderr, "Error closing connection socket (%s)\n",
     409                            str_error(rc));
     410                        closesocket(listen_sd);
     411                        return 5;
     412                }
     413               
     414                fprintf(stderr, "Connection closed\n");
     415        }
     416       
     417        /* Not reached */
    139418        return 0;
    140419}
Note: See TracChangeset for help on using the changeset viewer.