Changeset 694ca93f in mainline for uspace/app


Ignore:
Timestamp:
2011-05-01T19:34:26Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e26444
Parents:
1ff896e (diff), 042fbe0 (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:
4 added
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r1ff896e r694ca93f  
    3939#include <io/color.h>
    4040#include <io/style.h>
     41#include <io/keycode.h>
    4142#include <errno.h>
    4243#include <vfs/vfs.h>
     
    6263static sysarg_t console_cols = 0;
    6364static sysarg_t console_rows = 0;
     65static bool should_quit = false;
    6466
    6567static struct option const long_options[] = {
     
    102104        console_set_pos(fphone(stdout), 0, console_rows-1);
    103105        console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0);
    104         printf("Press any key to continue");
     106        printf("ENTER/SPACE/PAGE DOWN - next page, "
     107               "ESC/Q - quit, C - continue unpaged");
    105108        fflush(stdout);
    106109        console_set_style(fphone(stdout), STYLE_NORMAL);
     
    116119                }
    117120                if (ev.type == KEY_PRESS) {
    118                         return;
     121                        if (ev.key == KC_ESCAPE || ev.key == KC_Q) {
     122                                should_quit = true;
     123                                return;
     124                        }
     125                        if (ev.key == KC_C) {
     126                                paging_enabled = false;
     127                                return;
     128                        }
     129                        if (ev.key == KC_ENTER || ev.key == KC_SPACE ||
     130                            ev.key == KC_PAGE_DOWN) {
     131                                return;
     132                        }
    119133                }
    120134        }
     
    150164{
    151165        int fd, bytes = 0, count = 0, reads = 0;
    152         off64_t total = 0;
    153166        char *buff = NULL;
    154167        int i;
     
    160173                return 1;
    161174        }
    162 
    163         total = lseek(fd, 0, SEEK_END);
    164         lseek(fd, 0, SEEK_SET);
    165175
    166176        if (NULL == (buff = (char *) malloc(blen + 1))) {
     
    177187                        buff[bytes] = '\0';
    178188                        offset = 0;
    179                         for (i = 0; i < bytes; i++) {
     189                        for (i = 0; i < bytes && !should_quit; i++) {
    180190                                if (hex) {
    181191                                        paged_char(hexchars[((uint8_t)buff[i])/16]);
     
    185195                                        wchar_t c = str_decode(buff, &offset, bytes);
    186196                                        if (c == 0) {
    187                                                 // reached end of string
     197                                                /* Reached end of string */
    188198                                                break;
    189199                                        }
     
    194204                        reads++;
    195205                }
    196         } while (bytes > 0);
     206        } while (bytes > 0 && !should_quit);
    197207
    198208        close(fd);
     
    218228        int rc;
    219229       
    220         // reset global state
    221         // TODO: move to structure?
     230        /*
     231         * reset global state
     232         * TODO: move to structure?
     233         */
    222234        paging_enabled = false;
    223235        chars_remaining = 0;
     
    225237        console_cols = 0;
    226238        console_rows = 0;
     239        should_quit = false;
    227240
    228241        argc = cli_count_args(argv);
     
    278291        }
    279292
    280         for (i = optind; argv[i] != NULL; i++)
     293        for (i = optind; argv[i] != NULL && !should_quit; i++)
    281294                ret += cat_file(argv[i], buffer, hex);
    282295
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r1ff896e r694ca93f  
    108108        for (;;) {
    109109                ssize_t res;
     110                size_t written = 0;
    110111
    111112                bytes = read(fd1, buff, blen);
     
    120121                         * returned less data than requested.
    121122                         */
    122                         bytes = write(fd2, buff, res);
     123                        bytes = write(fd2, buff + written, res);
    123124                        if (bytes < 0)
    124125                                goto err;
     126                        written += bytes;
    125127                        res -= bytes;
    126128                } while (res > 0);
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r1ff896e r694ca93f  
    3838#include <dirent.h>
    3939#include <fcntl.h>
     40#include <getopt.h>
    4041#include <sys/types.h>
    4142#include <sys/stat.h>
    4243#include <str.h>
     44#include <sort.h>
    4345
    4446#include "errors.h"
     
    4648#include "util.h"
    4749#include "entry.h"
    48 #include "ls.h"
    4950#include "cmds.h"
    5051
     52/* Various values that can be returned by ls_scope() */
     53#define LS_BOGUS 0
     54#define LS_FILE  1
     55#define LS_DIR   2
     56
     57/** Structure to represent a directory entry.
     58 *
     59 * Useful to keep together important information
     60 * for sorting directory entries.
     61 */
     62struct dir_elem_t {
     63        char *name;
     64        struct stat s;
     65};
     66
    5167static const char *cmdname = "ls";
    5268
    53 static void ls_scan_dir(const char *d, DIR *dirp)
    54 {
     69static struct option const long_options[] = {
     70        { "help", no_argument, 0, 'h' },
     71        { "unsort", no_argument, 0, 'u' },
     72        { 0, 0, 0, 0 }
     73};
     74
     75/** Print an entry.
     76 *
     77 * ls_print currently does nothing more than print the entry.
     78 * In the future, we will likely pass the absolute path, and
     79 * some sort of ls_options structure that controls how each
     80 * entry is printed and what is printed about it.
     81 *
     82 * Now we just print basic DOS style lists.
     83 *
     84 * @param de            Directory element.
     85 */
     86static void ls_print(struct dir_elem_t *de)
     87{
     88        if (de->s.is_file)
     89                printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
     90        else if (de->s.is_directory)
     91                printf("%-40s\t<dir>\n", de->name);
     92        else
     93                printf("%-40s\n", de->name);
     94}
     95
     96
     97/** Compare 2 directory elements.
     98 *
     99 * It compares 2 elements of a directory : a file is considered
     100 * as bigger than a directory, and if they have the same type,
     101 * they are compared alphabetically.
     102 *
     103 * @param a             Pointer to the structure of the first element.
     104 * @param b             Pointer to the structure of the second element.
     105 * @param arg           Pointer for an other and optionnal argument.
     106 *
     107 * @return              -1 if a < b, 1 otherwise.
     108 */
     109static int ls_cmp(void *a, void *b, void *arg)
     110{
     111        struct dir_elem_t *da = a;
     112        struct dir_elem_t *db = b;
     113       
     114        if ((da->s.is_directory && db->s.is_file) ||
     115            ((da->s.is_directory == db->s.is_directory) &&
     116            str_cmp(da->name, db->name) < 0))
     117                return -1;
     118        else
     119                return 1;
     120}
     121
     122/** Scan a directory.
     123 *
     124 * Scan the content of a directory and print it.
     125 *
     126 * @param d             Name of the directory.
     127 * @param dirp  Directory stream.
     128 * @param sort  1 if the output must be sorted,
     129 *                              0 otherwise.
     130 */
     131static void ls_scan_dir(const char *d, DIR *dirp, int sort)
     132{
     133        int alloc_blocks = 20;
     134        int i;
     135        int nbdirs = 0;
     136        int rc;
     137        int len;
     138        char *buff;
     139        struct dir_elem_t *tmp;
     140        struct dir_elem_t *tosort;
    55141        struct dirent *dp;
    56         char *buff;
    57 
    58         if (! dirp)
     142       
     143        if (!dirp)
    59144                return;
    60145
    61         buff = (char *)malloc(PATH_MAX);
    62         if (NULL == buff) {
     146        buff = (char *) malloc(PATH_MAX);
     147        if (!buff) {
    63148                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
    64149                return;
    65150        }
    66 
     151       
     152        tosort = (struct dir_elem_t *) malloc(alloc_blocks * sizeof(*tosort));
     153        if (!tosort) {
     154                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     155                free(buff);
     156                return;
     157        }
     158       
    67159        while ((dp = readdir(dirp))) {
    68                 memset(buff, 0, sizeof(buff));
    69                 /* Don't worry if inserting a double slash, this will be fixed by
    70                  * absolutize() later with subsequent calls to open() or readdir() */
    71                 snprintf(buff, PATH_MAX - 1, "%s/%s", d, dp->d_name);
    72                 ls_print(dp->d_name, buff);
    73         }
    74 
     160                if (nbdirs + 1 > alloc_blocks) {
     161                        alloc_blocks += alloc_blocks;
     162                       
     163                        tmp = (struct dir_elem_t *) realloc(tosort,
     164                            alloc_blocks * sizeof(struct dir_elem_t));
     165                        if (!tmp) {
     166                                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     167                                goto out;
     168                        }
     169                        tosort = tmp;
     170                }
     171               
     172                /* fill the name field */
     173                tosort[nbdirs].name = (char *) malloc(str_length(dp->d_name) + 1);
     174                if (!tosort[nbdirs].name) {
     175                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     176                        goto out;
     177                }
     178               
     179                str_cpy(tosort[nbdirs].name, str_length(dp->d_name) + 1, dp->d_name);
     180                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
     181                buff[len] = '\0';
     182
     183                rc = stat(buff, &tosort[nbdirs++].s);
     184                if (rc != 0) {
     185                        printf("ls: skipping bogus node %s\n", buff);
     186                        printf("rc=%d\n", rc);
     187                        goto out;
     188                }
     189        }
     190       
     191        if (sort) {
     192                if (!qsort(&tosort[0], nbdirs, sizeof(struct dir_elem_t),
     193                    ls_cmp, NULL)) {
     194                        printf("Sorting error.\n");
     195                }
     196        }
     197       
     198        for (i = 0; i < nbdirs; i++)
     199                ls_print(&tosort[i]);
     200       
     201out:
     202        for(i = 0; i < nbdirs; i++)
     203                free(tosort[i].name);
     204        free(tosort);
    75205        free(buff);
    76 
    77         return;
    78 }
    79 
    80 /* ls_print currently does nothing more than print the entry.
    81  * in the future, we will likely pass the absolute path, and
    82  * some sort of ls_options structure that controls how each
    83  * entry is printed and what is printed about it.
    84  *
    85  * Now we just print basic DOS style lists */
    86 
    87 static void ls_print(const char *name, const char *pathname)
    88 {
    89         struct stat s;
    90         int rc;
    91 
    92         rc = stat(pathname, &s);
    93         if (rc != 0) {
    94                 /* Odd chance it was deleted from the time readdir() found it */
    95                 printf("ls: skipping bogus node %s\n", pathname);
    96                 printf("rc=%d\n", rc);
    97                 return;
    98         }
    99        
    100         if (s.is_file)
    101                 printf("%-40s\t%llu\n", name, (long long) s.size);
    102         else if (s.is_directory)
    103                 printf("%-40s\t<dir>\n", name);
    104         else
    105                 printf("%-40s\n", name);
    106 
    107         return;
    108206}
    109207
     
    114212        } else {
    115213                help_cmd_ls(HELP_SHORT);
    116                 printf("  `%s' [path], if no path is given the current "
    117                                 "working directory is used.\n", cmdname);
     214                printf(
     215                "Usage:  %s [options] [path]\n"
     216                "If not path is given, the current working directory is used.\n"
     217                "Options:\n"
     218                "  -h, --help       A short option summary\n"
     219                "  -u, --unsort     Do not sort directory entries\n",
     220                cmdname);
    118221        }
    119222
     
    124227{
    125228        unsigned int argc;
    126         struct stat s;
    127         char *buff;
     229        struct dir_elem_t de;
    128230        DIR *dirp;
     231        int c, opt_ind;
     232        int sort = 1;
    129233
    130234        argc = cli_count_args(argv);
    131 
    132         buff = (char *) malloc(PATH_MAX);
    133         if (NULL == buff) {
     235       
     236        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
     237                c = getopt_long(argc, argv, "hu", long_options, &opt_ind);
     238                switch (c) {
     239                case 'h':
     240                        help_cmd_ls(HELP_LONG);
     241                        return CMD_SUCCESS;
     242                case 'u':
     243                        sort = 0;
     244                        break;
     245                }
     246        }
     247       
     248        argc -= optind;
     249       
     250        de.name = (char *) malloc(PATH_MAX);
     251        if (!de.name) {
    134252                cli_error(CL_ENOMEM, "%s: ", cmdname);
    135253                return CMD_FAILURE;
    136254        }
    137         memset(buff, 0, sizeof(buff));
    138 
    139         if (argc == 1)
    140                 getcwd(buff, PATH_MAX);
     255        memset(de.name, 0, sizeof(PATH_MAX));
     256       
     257        if (argc == 0)
     258                getcwd(de.name, PATH_MAX);
    141259        else
    142                 str_cpy(buff, PATH_MAX, argv[1]);
    143 
    144         if (stat(buff, &s)) {
    145                 cli_error(CL_ENOENT, buff);
    146                 free(buff);
     260                str_cpy(de.name, PATH_MAX, argv[optind]);
     261       
     262        if (stat(de.name, &de.s)) {
     263                cli_error(CL_ENOENT, de.name);
     264                free(de.name);
    147265                return CMD_FAILURE;
    148266        }
    149267
    150         if (s.is_file) {
    151                 ls_print(buff, buff);
     268        if (de.s.is_file) {
     269                ls_print(&de);
    152270        } else {
    153                 dirp = opendir(buff);
     271                dirp = opendir(de.name);
    154272                if (!dirp) {
    155273                        /* May have been deleted between scoping it and opening it */
    156                         cli_error(CL_EFAIL, "Could not stat %s", buff);
    157                         free(buff);
     274                        cli_error(CL_EFAIL, "Could not stat %s", de.name);
     275                        free(de.name);
    158276                        return CMD_FAILURE;
    159277                }
    160                 ls_scan_dir(buff, dirp);
     278                ls_scan_dir(de.name, dirp, sort);
    161279                closedir(dirp);
    162280        }
    163281
    164         free(buff);
     282        free(de.name);
    165283
    166284        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r1ff896e r694ca93f  
    101101}
    102102
     103static unsigned int rm_recursive_not_empty_dirs(const char *path)
     104{
     105        DIR *dirp;
     106        struct dirent *dp;
     107        char buff[PATH_MAX];
     108        unsigned int scope;
     109        unsigned int ret = 0;
     110
     111        dirp = opendir(path);
     112        if (!dirp) {
     113                /* May have been deleted between scoping it and opening it */
     114                cli_error(CL_EFAIL, "Could not open %s", path);
     115                return ret;
     116        }
     117
     118        memset(buff, 0, sizeof(buff));
     119        while ((dp = readdir(dirp))) {
     120                snprintf(buff, PATH_MAX - 1, "%s/%s", path, dp->d_name);
     121                scope = rm_scope(buff);
     122                switch (scope) {
     123                case RM_BOGUS:
     124                        break;
     125                case RM_FILE:
     126                        ret += rm_single(buff);
     127                        break;
     128                case RM_DIR:
     129                        ret += rm_recursive(buff);
     130                        break;
     131                }
     132        }
     133       
     134        return ret;
     135}
     136
    103137static unsigned int rm_recursive(const char *path)
    104138{
    105139        int rc;
     140        unsigned int ret = 0;
    106141
    107142        /* First see if it will just go away */
     
    111146
    112147        /* Its not empty, recursively scan it */
    113         cli_error(CL_ENOTSUP,
    114                 "Can not remove %s, directory not empty", path);
    115         return 1;
     148        ret = rm_recursive_not_empty_dirs(path);
     149
     150        /* Delete directory */
     151        rc = rmdir(path);
     152        if (rc == 0)
     153                return ret;
     154
     155        cli_error(CL_ENOTSUP, "Can not remove %s", path);
     156
     157        return ret + 1;
    116158}
    117159
  • uspace/app/init/Makefile

    r1ff896e r694ca93f  
    3030USPACE_PREFIX = ../..
    3131BINARY = init
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/app/init/init.c

    r1ff896e r694ca93f  
    272272        mount_tmpfs();
    273273       
     274#ifdef CONFIG_START_DEVMAN
     275        spawn("/srv/devman");
     276#endif
    274277        spawn("/srv/apic");
    275278        spawn("/srv/i8259");
  • uspace/app/klog/klog.c

    r1ff896e r694ca93f  
    118118        }
    119119       
    120         /*
    121          * Mode "a" would be definitively much better here, but it is
    122          * not well supported by the FAT driver.
    123          */
    124         log = fopen(LOG_FNAME, "w");
     120        log = fopen(LOG_FNAME, "a");
    125121        if (log == NULL)
    126122                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
  • uspace/app/sbi/src/run_expr.c

    r1ff896e r694ca93f  
    25292529        if (rc1 == EOK)
    25302530                rc2 = os_str_get_char(string->value, elem_index, &cval);
     2531        else
     2532                rc2 = EOK;
    25312533
    25322534        if (rc1 != EOK || rc2 != EOK) {
  • uspace/app/stats/stats.c

    r1ff896e r694ca93f  
    6969        size_t i;
    7070        for (i = 0; i < count; i++) {
    71                 uint64_t resmem, virtmem, ucycles, kcycles;
    72                 char resmem_suffix, virtmem_suffix, usuffix, ksuffix;
    73                
    74                 order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix);
    75                 order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix);
     71                uint64_t resmem;
     72                uint64_t virtmem;
     73                uint64_t ucycles;
     74                uint64_t kcycles;
     75                const char *resmem_suffix;
     76                const char *virtmem_suffix;
     77                char usuffix;
     78                char ksuffix;
     79               
     80                bin_order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix, true);
     81                bin_order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix, true);
    7682                order_suffix(stats_tasks[i].ucycles, &ucycles, &usuffix);
    7783                order_suffix(stats_tasks[i].kcycles, &kcycles, &ksuffix);
    7884               
    79                 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c %8" PRIu64 "%c"
     85                printf("%-8" PRIu64 " %7zu %7" PRIu64 "%s %6" PRIu64 "%s"
    8086                    " %8" PRIu64 "%c %8" PRIu64 "%c %s\n",
    8187                    stats_tasks[i].task_id, stats_tasks[i].threads,
  • uspace/app/tester/Makefile

    r1ff896e r694ca93f  
    5252        loop/loop1.c \
    5353        mm/malloc1.c \
     54        mm/malloc2.c \
     55        devs/devman1.c \
    5456        hw/misc/virtchar1.c \
    5557        hw/serial/serial1.c \
  • uspace/app/tester/fault/fault2.c

    r1ff896e r694ca93f  
    2929
    3030#include "../tester.h"
     31#include <stdio.h>
    3132
    3233typedef int __attribute__((may_alias)) aliasing_int;
     
    3839       
    3940        var1 = *((aliasing_int *) (((char *) (&var)) + 1));
     41        printf("Read %d\n", var1);
    4042       
    4143        return "Survived unaligned read";
  • uspace/app/tester/tester.c

    r1ff896e r694ca93f  
    6262#include "loop/loop1.def"
    6363#include "mm/malloc1.def"
     64#include "mm/malloc2.def"
    6465#include "hw/serial/serial1.def"
    6566#include "hw/misc/virtchar1.def"
    6667#include "libext2/libext2_1.def"
     68#include "devs/devman1.def"
    6769        {NULL, NULL, NULL, false}
    6870};
  • uspace/app/tester/tester.h

    r1ff896e r694ca93f  
    7878extern const char *test_loop1(void);
    7979extern const char *test_malloc1(void);
     80extern const char *test_malloc2(void);
    8081extern const char *test_serial1(void);
    8182extern const char *test_virtchar1(void);
    8283extern const char *test_libext2_1(void);
     84extern const char *test_devman1(void);
    8385
    8486extern test_t tests[];
  • uspace/app/top/screen.c

    r1ff896e r694ca93f  
    254254        uint64_t used;
    255255        uint64_t free;
    256         char total_suffix;
    257         char unavail_suffix;
    258         char used_suffix;
    259         char free_suffix;
    260        
    261         order_suffix(data->physmem->total, &total, &total_suffix);
    262         order_suffix(data->physmem->unavail, &unavail, &unavail_suffix);
    263         order_suffix(data->physmem->used, &used, &used_suffix);
    264         order_suffix(data->physmem->free, &free, &free_suffix);
    265        
    266         printf("memory: %" PRIu64 "%c total, %" PRIu64 "%c unavail, %"
    267             PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix,
     256        const char *total_suffix;
     257        const char *unavail_suffix;
     258        const char *used_suffix;
     259        const char *free_suffix;
     260       
     261        bin_order_suffix(data->physmem->total, &total, &total_suffix, false);
     262        bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false);
     263        bin_order_suffix(data->physmem->used, &used, &used_suffix, false);
     264        bin_order_suffix(data->physmem->free, &free, &free_suffix, false);
     265       
     266        printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %"
     267            PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix,
    268268            unavail, unavail_suffix, used, used_suffix, free, free_suffix);
    269269        screen_newline();
     
    295295               
    296296                uint64_t resmem;
    297                 char resmem_suffix;
    298                 order_suffix(task->resmem, &resmem, &resmem_suffix);
     297                const char *resmem_suffix;
     298                bin_order_suffix(task->resmem, &resmem, &resmem_suffix, true);
    299299               
    300300                uint64_t virtmem;
    301                 char virtmem_suffix;
    302                 order_suffix(task->virtmem, &virtmem, &virtmem_suffix);
    303                
    304                 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c ",
     301                const char *virtmem_suffix;
     302                bin_order_suffix(task->virtmem, &virtmem, &virtmem_suffix, true);
     303               
     304                printf("%-8" PRIu64 " %7zu %7" PRIu64 "%s ",
    305305                    task->task_id, task->threads, resmem, resmem_suffix);
    306306                print_percent(perc->resmem, 2);
    307                 printf(" %8" PRIu64 "%c ", virtmem, virtmem_suffix);
     307                printf(" %6" PRIu64 "%s ", virtmem, virtmem_suffix);
    308308                print_percent(perc->virtmem, 2);
    309309                puts(" ");
  • uspace/app/trace/trace.c

    r1ff896e r694ca93f  
    5353#include <libc.h>
    5454
    55 // Temporary: service and method names
     55/* Temporary: service and method names */
    5656#include "proto.h"
    5757#include <ipc/services.h>
     
    872872static display_mask_t parse_display_mask(const char *text)
    873873{
    874         display_mask_t dm;
     874        display_mask_t dm = 0;
    875875        const char *c = text;
    876876       
Note: See TracChangeset for help on using the changeset viewer.