Changeset 20235a3 in mainline for uspace


Ignore:
Timestamp:
2010-09-02T20:55:28Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0c39b96
Parents:
0c61955 (diff), 3249673 (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
Files:
8 added
22 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r0c61955 r20235a3  
    6666        srv/hid/adb_mouse \
    6767        srv/hid/char_mouse \
     68        srv/hid/s3c24xx_ts \
    6869        srv/hid/fb \
    6970        srv/hid/kbd \
    7071        srv/hw/char/i8042 \
     72        srv/hw/char/s3c24xx_uart \
    7173        srv/hw/netif/dp8390 \
    7274        srv/net/cfg \
  • uspace/Makefile.common

    r0c61955 r20235a3  
    172172ifneq ($(BINARY),)
    173173%.disasm: $(BINARY)
     174ifeq ($(CONFIG_LINE_DEBUG),y)
     175        $(OBJDUMP) -d -S $< > $@
     176else
    174177        $(OBJDUMP) -d $< > $@
     178endif
    175179
    176180$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
  • uspace/app/init/init.c

    r0c61955 r20235a3  
    274274        srv_start("/srv/cuda_adb");
    275275        srv_start("/srv/i8042");
     276        srv_start("/srv/s3c24ser");
    276277        srv_start("/srv/adb_ms");
    277278        srv_start("/srv/char_ms");
     279        srv_start("/srv/s3c24ts");
    278280       
    279281        spawn("/srv/fb");
  • uspace/app/klog/klog.c

    r0c61955 r20235a3  
    4343#include <event.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <io/klog.h>
    4647
    47 #define NAME  "klog"
     48#define NAME       "klog"
     49#define LOG_FNAME  "/log/klog"
    4850
    4951/* Pointer to klog area */
    5052static wchar_t *klog;
    5153static size_t klog_length;
     54
     55static FILE *log;
    5256
    5357static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     
    5862        size_t i;
    5963       
    60         for (i = klog_len - klog_stored; i < klog_len; i++)
    61                 putchar(klog[(klog_start + i) % klog_length]);
     64        for (i = klog_len - klog_stored; i < klog_len; i++) {
     65                wchar_t ch = klog[(klog_start + i) % klog_length];
     66               
     67                putchar(ch);
     68               
     69                if (log != NULL)
     70                        fputc(ch, log);
     71        }
     72       
     73        if (log != NULL) {
     74                fflush(log);
     75                fsync(fileno(log));
     76        }
    6277}
    6378
     
    91106        }
    92107       
     108        /*
     109         * Mode "a" would be definitively much better here, but it is
     110         * not well supported by the FAT driver.
     111         *
     112         */
     113        log = fopen(LOG_FNAME, "w");
     114        if (log == NULL)
     115                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
     116                    str_error(errno));
     117       
    93118        async_set_interrupt_received(interrupt_received);
    94119        klog_update();
  • uspace/lib/c/Makefile

    r0c61955 r20235a3  
    8484        generic/ipc.c \
    8585        generic/async.c \
     86        generic/async_rel.c \
    8687        generic/loader.c \
    8788        generic/getopt.c \
  • uspace/lib/c/generic/io/io.c

    r0c61955 r20235a3  
    757757}
    758758
     759int fileno(FILE *stream)
     760{
     761        if (stream->klog) {
     762                errno = EBADF;
     763                return -1;
     764        }
     765       
     766        return stream->fd;
     767}
     768
    759769int fphone(FILE *stream)
    760770{
  • uspace/lib/c/generic/libc.c

    r0c61955 r20235a3  
    5050#include <ipc/ipc.h>
    5151#include <async.h>
     52#include <async_rel.h>
    5253#include <as.h>
    5354#include <loader/pcb.h>
     
    6566        __heap_init();
    6667        __async_init();
     68        (void) async_rel_init();
    6769        fibril_t *fibril = fibril_setup();
    6870        __tcb_set(fibril->tcb);
  • uspace/lib/c/include/stdio.h

    r0c61955 r20235a3  
    171171extern off64_t ftell(FILE *);
    172172extern int feof(FILE *);
     173extern int fileno(FILE *);
    173174
    174175extern int fflush(FILE *);
  • uspace/srv/fs/fat/fat.h

    r0c61955 r20235a3  
    4848
    4949#define min(a, b)               ((a) < (b) ? (a) : (b))
     50
     51/*
     52 * Convenience macros for accessing some frequently used boot sector members.
     53 */
     54#define BPS(bs)         uint16_t_le2host((bs)->bps)
     55#define SPC(bs)         (bs)->spc
     56#define RSCNT(bs)       uint16_t_le2host((bs)->rscnt)
     57#define FATCNT(bs)      (bs)->fatcnt
     58#define SF(bs)          uint16_t_le2host((bs)->sec_per_fat)
     59#define RDE(bs)         uint16_t_le2host((bs)->root_ent_max)
     60#define TS(bs)          (uint16_t_le2host((bs)->totsec16) != 0 ? \
     61                        uint16_t_le2host((bs)->totsec16) : \
     62                        uint32_t_le2host(bs->totsec32))
    5063
    5164#define BS_BLOCK                0
     
    198211        unsigned                refcnt;
    199212        bool                    dirty;
     213
     214        /*
     215         * Cache of the node's last and "current" cluster to avoid some
     216         * unnecessary FAT walks.
     217         */
     218        /* Node's last cluster in FAT. */
     219        bool            lastc_cached_valid;
     220        fat_cluster_t   lastc_cached_value;
     221        /* Node's "current" cluster, i.e. where the last I/O took place. */
     222        bool            currc_cached_valid;
     223        aoff64_t        currc_cached_bn;
     224        fat_cluster_t   currc_cached_value;
    200225} fat_node_t;
    201226
  • uspace/srv/fs/fat/fat_fat.c

    r0c61955 r20235a3  
    4949#include <mem.h>
    5050
     51/*
     52 * Convenience macros for computing some frequently used values from the
     53 * primitive boot sector members.
     54 */
     55#define RDS(bs)         ((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \
     56                        (((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0)
     57#define SSA(bs)         (RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs))
     58
     59#define CLBN2PBN(bs, cl, bn) \
     60        (SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))
     61
    5162/**
    5263 * The fat_alloc_lock mutex protects all copies of the File Allocation Table
     
    7485{
    7586        block_t *b;
    76         unsigned bps;
    77         unsigned rscnt;         /* block address of the first FAT */
    7887        uint16_t clusters = 0;
    7988        fat_cluster_t clst = firstc;
    8089        int rc;
    81 
    82         bps = uint16_t_le2host(bs->bps);
    83         rscnt = uint16_t_le2host(bs->rscnt);
    8490
    8591        if (firstc == FAT_CLST_RES0) {
     
    99105                if (lastc)
    100106                        *lastc = clst;  /* remember the last cluster number */
    101                 fsec = (clst * sizeof(fat_cluster_t)) / bps;
    102                 fidx = clst % (bps / sizeof(fat_cluster_t));
     107                fsec = (clst * sizeof(fat_cluster_t)) / BPS(bs);
     108                fidx = clst % (BPS(bs) / sizeof(fat_cluster_t));
    103109                /* read FAT1 */
    104                 rc = block_get(&b, dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE);
     110                rc = block_get(&b, dev_handle, RSCNT(bs) + fsec,
     111                    BLOCK_FLAGS_NONE);
    105112                if (rc != EOK)
    106113                        return rc;
     
    125132 * @param block         Pointer to a block pointer for storing result.
    126133 * @param bs            Buffer holding the boot sector of the file system.
    127  * @param dev_handle    Device handle of the file system.
    128  * @param firstc        First cluster used by the file. Can be zero if the file
    129  *                      is empty.
     134 * @param nodep         FAT node.
    130135 * @param bn            Block number.
    131136 * @param flags         Flags passed to libblock.
     
    134139 */
    135140int
     141fat_block_get(block_t **block, struct fat_bs *bs, fat_node_t *nodep,
     142    aoff64_t bn, int flags)
     143{
     144        fat_cluster_t firstc = nodep->firstc;
     145        fat_cluster_t currc;
     146        aoff64_t relbn = bn;
     147        int rc;
     148
     149        if (!nodep->size)
     150                return ELIMIT;
     151
     152        if (nodep->firstc == FAT_CLST_ROOT)
     153                goto fall_through;
     154
     155        if (((((nodep->size - 1) / BPS(bs)) / SPC(bs)) == bn / SPC(bs)) &&
     156            nodep->lastc_cached_valid) {
     157                /*
     158                 * This is a request to read a block within the last cluster
     159                 * when fortunately we have the last cluster number cached.
     160                 */
     161                return block_get(block, nodep->idx->dev_handle,
     162                    CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags);
     163        }
     164
     165        if (nodep->currc_cached_valid && bn >= nodep->currc_cached_bn) {
     166                /*
     167                 * We can start with the cluster cached by the previous call to
     168                 * fat_block_get().
     169                 */
     170                firstc = nodep->currc_cached_value;
     171                relbn -= (nodep->currc_cached_bn / SPC(bs)) * SPC(bs);
     172        }
     173
     174fall_through:
     175        rc = _fat_block_get(block, bs, nodep->idx->dev_handle, firstc,
     176            &currc, relbn, flags);
     177        if (rc != EOK)
     178                return rc;
     179       
     180        /*
     181         * Update the "current" cluster cache.
     182         */
     183        nodep->currc_cached_valid = true;
     184        nodep->currc_cached_bn = bn;
     185        nodep->currc_cached_value = currc;
     186
     187        return rc;
     188}
     189
     190/** Read block from file located on a FAT file system.
     191 *
     192 * @param block         Pointer to a block pointer for storing result.
     193 * @param bs            Buffer holding the boot sector of the file system.
     194 * @param dev_handle    Device handle of the file system.
     195 * @param fcl           First cluster used by the file. Can be zero if the file
     196 *                      is empty.
     197 * @param clp           If not NULL, address where the cluster containing bn
     198 *                      will be stored.
     199 *                      stored
     200 * @param bn            Block number.
     201 * @param flags         Flags passed to libblock.
     202 *
     203 * @return              EOK on success or a negative error code.
     204 */
     205int
    136206_fat_block_get(block_t **block, fat_bs_t *bs, dev_handle_t dev_handle,
    137     fat_cluster_t firstc, aoff64_t bn, int flags)
    138 {
    139         unsigned bps;
    140         unsigned rscnt;         /* block address of the first FAT */
    141         unsigned rde;
    142         unsigned rds;           /* root directory size */
    143         unsigned sf;
    144         unsigned ssa;           /* size of the system area */
     207    fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags)
     208{
    145209        uint16_t clusters;
    146210        unsigned max_clusters;
    147         fat_cluster_t lastc;
     211        fat_cluster_t c;
    148212        int rc;
    149213
     
    151215         * This function can only operate on non-zero length files.
    152216         */
    153         if (firstc == FAT_CLST_RES0)
     217        if (fcl == FAT_CLST_RES0)
    154218                return ELIMIT;
    155219
    156         bps = uint16_t_le2host(bs->bps);
    157         rscnt = uint16_t_le2host(bs->rscnt);
    158         rde = uint16_t_le2host(bs->root_ent_max);
    159         sf = uint16_t_le2host(bs->sec_per_fat);
    160 
    161         rds = (sizeof(fat_dentry_t) * rde) / bps;
    162         rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);
    163         ssa = rscnt + bs->fatcnt * sf + rds;
    164 
    165         if (firstc == FAT_CLST_ROOT) {
     220        if (fcl == FAT_CLST_ROOT) {
    166221                /* root directory special case */
    167                 assert(bn < rds);
    168                 rc = block_get(block, dev_handle, rscnt + bs->fatcnt * sf + bn,
    169                     flags);
     222                assert(bn < RDS(bs));
     223                rc = block_get(block, dev_handle,
     224                    RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags);
    170225                return rc;
    171226        }
    172227
    173         max_clusters = bn / bs->spc;
    174         rc = fat_cluster_walk(bs, dev_handle, firstc, &lastc, &clusters,
    175             max_clusters);
     228        max_clusters = bn / SPC(bs);
     229        rc = fat_cluster_walk(bs, dev_handle, fcl, &c, &clusters, max_clusters);
    176230        if (rc != EOK)
    177231                return rc;
    178232        assert(clusters == max_clusters);
    179233
    180         rc = block_get(block, dev_handle,
    181             ssa + (lastc - FAT_CLST_FIRST) * bs->spc + bn % bs->spc, flags);
     234        rc = block_get(block, dev_handle, CLBN2PBN(bs, c, bn), flags);
     235
     236        if (clp)
     237                *clp = c;
    182238
    183239        return rc;
     
    198254int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos)
    199255{
    200         uint16_t bps;
    201         unsigned spc;
    202256        block_t *b;
    203257        aoff64_t o, boundary;
    204258        int rc;
    205259
    206         bps = uint16_t_le2host(bs->bps);
    207         spc = bs->spc;
    208        
    209         boundary = ROUND_UP(nodep->size, bps * spc);
     260        boundary = ROUND_UP(nodep->size, BPS(bs) * SPC(bs));
    210261
    211262        /* zero out already allocated space */
    212263        for (o = nodep->size; o < pos && o < boundary;
    213             o = ALIGN_DOWN(o + bps, bps)) {
    214                 int flags = (o % bps == 0) ?
     264            o = ALIGN_DOWN(o + BPS(bs), BPS(bs))) {
     265                int flags = (o % BPS(bs) == 0) ?
    215266                    BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE;
    216                 rc = fat_block_get(&b, bs, nodep, o / bps, flags);
    217                 if (rc != EOK)
    218                         return rc;
    219                 memset(b->data + o % bps, 0, bps - o % bps);
     267                rc = fat_block_get(&b, bs, nodep, o / BPS(bs), flags);
     268                if (rc != EOK)
     269                        return rc;
     270                memset(b->data + o % BPS(bs), 0, BPS(bs) - o % BPS(bs));
    220271                b->dirty = true;                /* need to sync node */
    221272                rc = block_put(b);
     
    228279       
    229280        /* zero out the initial part of the new cluster chain */
    230         for (o = boundary; o < pos; o += bps) {
     281        for (o = boundary; o < pos; o += BPS(bs)) {
    231282                rc = _fat_block_get(&b, bs, nodep->idx->dev_handle, mcl,
    232                     (o - boundary) / bps, BLOCK_FLAGS_NOREAD);
    233                 if (rc != EOK)
    234                         return rc;
    235                 memset(b->data, 0, min(bps, pos - o));
     283                    NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD);
     284                if (rc != EOK)
     285                        return rc;
     286                memset(b->data, 0, min(BPS(bs), pos - o));
    236287                b->dirty = true;                /* need to sync node */
    237288                rc = block_put(b);
     
    257308{
    258309        block_t *b;
    259         uint16_t bps;
    260         uint16_t rscnt;
    261         uint16_t sf;
    262310        fat_cluster_t *cp;
    263311        int rc;
    264312
    265         bps = uint16_t_le2host(bs->bps);
    266         rscnt = uint16_t_le2host(bs->rscnt);
    267         sf = uint16_t_le2host(bs->sec_per_fat);
    268 
    269         rc = block_get(&b, dev_handle, rscnt + sf * fatno +
    270             (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
     313        rc = block_get(&b, dev_handle, RSCNT(bs) + SF(bs) * fatno +
     314            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    271315        if (rc != EOK)
    272316                return rc;
    273         cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
     317        cp = (fat_cluster_t *)b->data +
     318            clst % (BPS(bs) / sizeof(fat_cluster_t));
    274319        *value = uint16_t_le2host(*cp);
    275320        rc = block_put(b);
     
    293338{
    294339        block_t *b;
    295         uint16_t bps;
    296         uint16_t rscnt;
    297         uint16_t sf;
    298340        fat_cluster_t *cp;
    299341        int rc;
    300342
    301         bps = uint16_t_le2host(bs->bps);
    302         rscnt = uint16_t_le2host(bs->rscnt);
    303         sf = uint16_t_le2host(bs->sec_per_fat);
    304 
    305         assert(fatno < bs->fatcnt);
    306         rc = block_get(&b, dev_handle, rscnt + sf * fatno +
    307             (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
     343        assert(fatno < FATCNT(bs));
     344        rc = block_get(&b, dev_handle, RSCNT(bs) + SF(bs) * fatno +
     345            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    308346        if (rc != EOK)
    309347                return rc;
    310         cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
     348        cp = (fat_cluster_t *)b->data +
     349            clst % (BPS(bs) / sizeof(fat_cluster_t));
    311350        *cp = host2uint16_t_le(value);
    312351        b->dirty = true;                /* need to sync block */
     
    364403    fat_cluster_t *mcl, fat_cluster_t *lcl)
    365404{
    366         uint16_t bps;
    367         uint16_t rscnt;
    368         uint16_t sf;
    369         uint32_t ts;
    370         unsigned rde;
    371         unsigned rds;
    372         unsigned ssa;
    373405        block_t *blk;
    374406        fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
     
    380412        if (!lifo)
    381413                return ENOMEM;
    382        
    383         bps = uint16_t_le2host(bs->bps);
    384         rscnt = uint16_t_le2host(bs->rscnt);
    385         sf = uint16_t_le2host(bs->sec_per_fat);
    386         rde = uint16_t_le2host(bs->root_ent_max);
    387         ts = (uint32_t) uint16_t_le2host(bs->totsec16);
    388         if (ts == 0)
    389                 ts = uint32_t_le2host(bs->totsec32);
    390 
    391         rds = (sizeof(fat_dentry_t) * rde) / bps;
    392         rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);
    393         ssa = rscnt + bs->fatcnt * sf + rds;
    394414       
    395415        /*
     
    397417         */
    398418        fibril_mutex_lock(&fat_alloc_lock);
    399         for (b = 0, cl = 0; b < sf; b++) {
    400                 rc = block_get(&blk, dev_handle, rscnt + b, BLOCK_FLAGS_NONE);
     419        for (b = 0, cl = 0; b < SF(bs); b++) {
     420                rc = block_get(&blk, dev_handle, RSCNT(bs) + b,
     421                    BLOCK_FLAGS_NONE);
    401422                if (rc != EOK)
    402423                        goto error;
    403                 for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
     424                for (c = 0; c < BPS(bs) / sizeof(fat_cluster_t); c++, cl++) {
    404425                        /*
    405                          * Check if the cluster is physically there. This check
    406                          * becomes necessary when the file system is created
    407                          * with fewer total sectors than how many is inferred
    408                          * from the size of the file allocation table.
     426                         * Check if the entire cluster is physically there.
     427                         * This check becomes necessary when the file system is
     428                         * created with fewer total sectors than how many is
     429                         * inferred from the size of the file allocation table
     430                         * or when the last cluster ends beyond the end of the
     431                         * device.
    409432                         */
    410                         if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) {
     433                        if ((cl >= FAT_CLST_FIRST) &&
     434                            CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) {
    411435                                rc = block_put(blk);
    412436                                if (rc != EOK)
     
    511535 * @param nodep         Node representing the file.
    512536 * @param mcl           First cluster of the cluster chain to append.
     537 * @param lcl           Last cluster of the cluster chain to append.
    513538 *
    514539 * @return              EOK on success or a negative error code.
    515540 */
    516 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl)
     541int
     542fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl,
     543    fat_cluster_t lcl)
    517544{
    518545        dev_handle_t dev_handle = nodep->idx->dev_handle;
    519         fat_cluster_t lcl;
     546        fat_cluster_t lastc;
    520547        uint16_t numc;
    521548        uint8_t fatno;
    522549        int rc;
    523550
    524         rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc,
    525             (uint16_t) -1);
    526         if (rc != EOK)
    527                 return rc;
    528 
    529         if (numc == 0) {
    530                 /* No clusters allocated to the node yet. */
    531                 nodep->firstc = mcl;
    532                 nodep->dirty = true;            /* need to sync node */
    533                 return EOK;
     551        if (nodep->lastc_cached_valid) {
     552                lastc = nodep->lastc_cached_value;
     553                nodep->lastc_cached_valid = false;
     554        } else {
     555                rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lastc,
     556                    &numc, (uint16_t) -1);
     557                if (rc != EOK)
     558                        return rc;
     559
     560                if (numc == 0) {
     561                        /* No clusters allocated to the node yet. */
     562                        nodep->firstc = mcl;
     563                        nodep->dirty = true;    /* need to sync node */
     564                        return EOK;
     565                }
    534566        }
    535567
    536568        for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    537                 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl,
     569                rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lastc,
    538570                    mcl);
    539571                if (rc != EOK)
    540572                        return rc;
    541573        }
     574
     575        nodep->lastc_cached_valid = true;
     576        nodep->lastc_cached_value = lcl;
    542577
    543578        return EOK;
     
    548583 * @param bs            Buffer holding the boot sector of the file system.
    549584 * @param nodep         FAT node where the chopping will take place.
    550  * @param lastc         Last cluster which will remain in the node. If this
     585 * @param lcl           Last cluster which will remain in the node. If this
    551586 *                      argument is FAT_CLST_RES0, then all clusters will
    552587 *                      be chopped off.
     
    554589 * @return              EOK on success or a negative return code.
    555590 */
    556 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc)
    557 {
    558         int rc;
    559 
     591int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl)
     592{
     593        int rc;
    560594        dev_handle_t dev_handle = nodep->idx->dev_handle;
    561         if (lastc == FAT_CLST_RES0) {
     595
     596        /*
     597         * Invalidate cached cluster numbers.
     598         */
     599        nodep->lastc_cached_valid = false;
     600        if (nodep->currc_cached_value != lcl)
     601                nodep->currc_cached_valid = false;
     602
     603        if (lcl == FAT_CLST_RES0) {
    562604                /* The node will have zero size and no clusters allocated. */
    563605                rc = fat_free_clusters(bs, dev_handle, nodep->firstc);
     
    570612                unsigned fatno;
    571613
    572                 rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc);
     614                rc = fat_get_cluster(bs, dev_handle, FAT1, lcl, &nextc);
    573615                if (rc != EOK)
    574616                        return rc;
     
    576618                /* Terminate the cluster chain in all copies of FAT. */
    577619                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    578                         rc = fat_set_cluster(bs, dev_handle, fatno, lastc,
     620                        rc = fat_set_cluster(bs, dev_handle, fatno, lcl,
    579621                            FAT_CLST_LAST1);
    580622                        if (rc != EOK)
     
    588630        }
    589631
     632        /*
     633         * Update and re-enable the last cluster cache.
     634         */
     635        nodep->lastc_cached_valid = true;
     636        nodep->lastc_cached_value = lcl;
     637
    590638        return EOK;
    591639}
     
    596644        int i;
    597645        block_t *b;
    598         unsigned bps;
    599         int rc;
    600 
    601         bps = uint16_t_le2host(bs->bps);
    602        
    603         for (i = 0; i < bs->spc; i++) {
    604                 rc = _fat_block_get(&b, bs, dev_handle, c, i,
     646        int rc;
     647
     648        for (i = 0; i < SPC(bs); i++) {
     649                rc = _fat_block_get(&b, bs, dev_handle, c, NULL, i,
    605650                    BLOCK_FLAGS_NOREAD);
    606651                if (rc != EOK)
    607652                        return rc;
    608                 memset(b->data, 0, bps);
     653                memset(b->data, 0, BPS(bs));
    609654                b->dirty = true;
    610655                rc = block_put(b);
  • uspace/srv/fs/fat/fat_fat.h

    r0c61955 r20235a3  
    6464    fat_cluster_t *, uint16_t *, uint16_t);
    6565
    66 #define fat_block_get(b, bs, np, bn, flags) \
    67     _fat_block_get((b), (bs), (np)->idx->dev_handle, (np)->firstc, (bn), \
    68     (flags))
    69 
     66extern int fat_block_get(block_t **, struct fat_bs *, struct fat_node *,
     67    aoff64_t, int);
    7068extern int _fat_block_get(block_t **, struct fat_bs *, dev_handle_t,
    71     fat_cluster_t, aoff64_t, int);
     69    fat_cluster_t, fat_cluster_t *, aoff64_t, int);
    7270
    7371extern int fat_append_clusters(struct fat_bs *, struct fat_node *,
    74     fat_cluster_t);
     72    fat_cluster_t, fat_cluster_t);
    7573extern int fat_chop_clusters(struct fat_bs *, struct fat_node *,
    7674    fat_cluster_t);
  • uspace/srv/fs/fat/fat_ops.c

    r0c61955 r20235a3  
    6060#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
    6161
     62#define DPS(bs)         (BPS((bs)) / sizeof(fat_dentry_t))
     63#define BPC(bs)         (BPS((bs)) * SPC((bs)))
     64
    6265/** Mutex protecting the list of cached free FAT nodes. */
    6366static FIBRIL_MUTEX_INITIALIZE(ffn_mutex);
     
    101104        node->refcnt = 0;
    102105        node->dirty = false;
     106        node->lastc_cached_valid = false;
     107        node->lastc_cached_value = FAT_CLST_LAST1;
     108        node->currc_cached_valid = false;
     109        node->currc_cached_bn = 0;
     110        node->currc_cached_value = FAT_CLST_LAST1;
    103111}
    104112
     
    108116        fat_bs_t *bs;
    109117        fat_dentry_t *d;
    110         uint16_t bps;
    111         unsigned dps;
    112118        int rc;
    113119       
     
    115121
    116122        bs = block_bb_get(node->idx->dev_handle);
    117         bps = uint16_t_le2host(bs->bps);
    118         dps = bps / sizeof(fat_dentry_t);
    119123       
    120124        /* Read the block that contains the dentry of interest. */
    121125        rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc,
    122             (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     126            NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
     127            BLOCK_FLAGS_NONE);
    123128        if (rc != EOK)
    124129                return rc;
    125130
    126         d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
     131        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs));
    127132
    128133        d->firstc = host2uint16_t_le(node->firstc);
     
    266271        fat_dentry_t *d;
    267272        fat_node_t *nodep = NULL;
    268         unsigned bps;
    269         unsigned spc;
    270         unsigned dps;
    271273        int rc;
    272274
     
    298300
    299301        bs = block_bb_get(idxp->dev_handle);
    300         bps = uint16_t_le2host(bs->bps);
    301         spc = bs->spc;
    302         dps = bps / sizeof(fat_dentry_t);
    303302
    304303        /* Read the block that contains the dentry of interest. */
    305         rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc,
    306             (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     304        rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, NULL,
     305            (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    307306        if (rc != EOK) {
    308307                (void) fat_node_put(FS_NODE(nodep));
     
    310309        }
    311310
    312         d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
     311        d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
    313312        if (d->attr & FAT_ATTR_SUBDIR) {
    314313                /*
     
    330329                        return rc;
    331330                }
    332                 nodep->size = bps * spc * clusters;
     331                nodep->size = BPS(bs) * SPC(bs) * clusters;
    333332        } else {
    334333                nodep->type = FAT_FILE;
     
    368367        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    369368        unsigned i, j;
    370         unsigned bps;           /* bytes per sector */
    371         unsigned dps;           /* dentries per sector */
    372369        unsigned blocks;
    373370        fat_dentry_t *d;
     
    377374        fibril_mutex_lock(&parentp->idx->lock);
    378375        bs = block_bb_get(parentp->idx->dev_handle);
    379         bps = uint16_t_le2host(bs->bps);
    380         dps = bps / sizeof(fat_dentry_t);
    381         blocks = parentp->size / bps;
     376        blocks = parentp->size / BPS(bs);
    382377        for (i = 0; i < blocks; i++) {
    383378                rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    386381                        return rc;
    387382                }
    388                 for (j = 0; j < dps; j++) {
     383                for (j = 0; j < DPS(bs); j++) {
    389384                        d = ((fat_dentry_t *)b->data) + j;
    390385                        switch (fat_classify_dentry(d)) {
     
    414409                                fat_idx_t *idx = fat_idx_get_by_pos(
    415410                                    parentp->idx->dev_handle, parentp->firstc,
    416                                     i * dps + j);
     411                                    i * DPS(bs) + j);
    417412                                fibril_mutex_unlock(&parentp->idx->lock);
    418413                                if (!idx) {
     
    513508        fat_bs_t *bs;
    514509        fat_cluster_t mcl, lcl;
    515         uint16_t bps;
    516510        int rc;
    517511
    518512        bs = block_bb_get(dev_handle);
    519         bps = uint16_t_le2host(bs->bps);
    520513        if (flags & L_DIRECTORY) {
    521514                /* allocate a cluster */
     
    546539                nodep->type = FAT_DIRECTORY;
    547540                nodep->firstc = mcl;
    548                 nodep->size = bps * bs->spc;
     541                nodep->size = BPS(bs) * SPC(bs);
    549542        } else {
    550543                nodep->type = FAT_FILE;
     
    609602        block_t *b;
    610603        unsigned i, j;
    611         uint16_t bps;
    612         unsigned dps;
    613604        unsigned blocks;
    614605        fat_cluster_t mcl, lcl;
     
    640631        fibril_mutex_lock(&parentp->idx->lock);
    641632        bs = block_bb_get(parentp->idx->dev_handle);
    642         bps = uint16_t_le2host(bs->bps);
    643         dps = bps / sizeof(fat_dentry_t);
    644 
    645         blocks = parentp->size / bps;
     633
     634        blocks = parentp->size / BPS(bs);
    646635
    647636        for (i = 0; i < blocks; i++) {
     
    651640                        return rc;
    652641                }
    653                 for (j = 0; j < dps; j++) {
     642                for (j = 0; j < DPS(bs); j++) {
    654643                        d = ((fat_dentry_t *)b->data) + j;
    655644                        switch (fat_classify_dentry(d)) {
     
    691680                return rc;
    692681        }
    693         rc = fat_append_clusters(bs, parentp, mcl);
     682        rc = fat_append_clusters(bs, parentp, mcl, lcl);
    694683        if (rc != EOK) {
    695684                (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl);
     
    697686                return rc;
    698687        }
    699         parentp->size += bps * bs->spc;
     688        parentp->size += BPS(bs) * SPC(bs);
    700689        parentp->dirty = true;          /* need to sync node */
    701690        rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    771760
    772761        childp->idx->pfc = parentp->firstc;
    773         childp->idx->pdi = i * dps + j;
     762        childp->idx->pdi = i * DPS(bs) + j;
    774763        fibril_mutex_unlock(&childp->idx->lock);
    775764
     
    793782        fat_bs_t *bs;
    794783        fat_dentry_t *d;
    795         uint16_t bps;
    796784        block_t *b;
    797785        bool has_children;
     
    812800        fibril_mutex_lock(&childp->idx->lock);
    813801        bs = block_bb_get(childp->idx->dev_handle);
    814         bps = uint16_t_le2host(bs->bps);
    815802
    816803        rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc,
    817             (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
     804            NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
    818805            BLOCK_FLAGS_NONE);
    819806        if (rc != EOK)
    820807                goto error;
    821808        d = (fat_dentry_t *)b->data +
    822             (childp->idx->pdi % (bps / sizeof(fat_dentry_t)));
     809            (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t)));
    823810        /* mark the dentry as not-currently-used */
    824811        d->name[0] = FAT_DENTRY_ERASED;
     
    852839        fat_bs_t *bs;
    853840        fat_node_t *nodep = FAT_NODE(fn);
    854         unsigned bps;
    855         unsigned dps;
    856841        unsigned blocks;
    857842        block_t *b;
     
    866851        fibril_mutex_lock(&nodep->idx->lock);
    867852        bs = block_bb_get(nodep->idx->dev_handle);
    868         bps = uint16_t_le2host(bs->bps);
    869         dps = bps / sizeof(fat_dentry_t);
    870 
    871         blocks = nodep->size / bps;
     853
     854        blocks = nodep->size / BPS(bs);
    872855
    873856        for (i = 0; i < blocks; i++) {
     
    879862                        return rc;
    880863                }
    881                 for (j = 0; j < dps; j++) {
     864                for (j = 0; j < DPS(bs); j++) {
    882865                        d = ((fat_dentry_t *)b->data) + j;
    883866                        switch (fat_classify_dentry(d)) {
     
    976959        enum cache_mode cmode;
    977960        fat_bs_t *bs;
    978         uint16_t bps;
    979         uint16_t rde;
    980961       
    981962        /* Accept the mount options */
     
    1014995        bs = block_bb_get(dev_handle);
    1015996       
    1016         /* Read the number of root directory entries. */
    1017         bps = uint16_t_le2host(bs->bps);
    1018         rde = uint16_t_le2host(bs->root_ent_max);
    1019 
    1020         if (bps != BS_SIZE) {
     997        if (BPS(bs) != BS_SIZE) {
    1021998                block_fini(dev_handle);
    1022999                ipc_answer_0(rid, ENOTSUP);
     
    10251002
    10261003        /* Initialize the block cache */
    1027         rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
     1004        rc = block_cache_init(dev_handle, BPS(bs), 0 /* XXX */, cmode);
    10281005        if (rc != EOK) {
    10291006                block_fini(dev_handle);
     
    10871064        rootp->refcnt = 1;
    10881065        rootp->lnkcnt = 0;      /* FS root is not linked */
    1089         rootp->size = rde * sizeof(fat_dentry_t);
     1066        rootp->size = RDE(bs) * sizeof(fat_dentry_t);
    10901067        rootp->idx = ridxp;
    10911068        ridxp->nodep = rootp;
     
    11651142        fat_node_t *nodep;
    11661143        fat_bs_t *bs;
    1167         uint16_t bps;
    11681144        size_t bytes;
    11691145        block_t *b;
     
    11911167
    11921168        bs = block_bb_get(dev_handle);
    1193         bps = uint16_t_le2host(bs->bps);
    11941169
    11951170        if (nodep->type == FAT_FILE) {
     
    12041179                        (void) async_data_read_finalize(callid, NULL, 0);
    12051180                } else {
    1206                         bytes = min(len, bps - pos % bps);
     1181                        bytes = min(len, BPS(bs) - pos % BPS(bs));
    12071182                        bytes = min(bytes, nodep->size - pos);
    1208                         rc = fat_block_get(&b, bs, nodep, pos / bps,
     1183                        rc = fat_block_get(&b, bs, nodep, pos / BPS(bs),
    12091184                            BLOCK_FLAGS_NONE);
    12101185                        if (rc != EOK) {
     
    12141189                                return;
    12151190                        }
    1216                         (void) async_data_read_finalize(callid, b->data + pos % bps,
    1217                             bytes);
     1191                        (void) async_data_read_finalize(callid,
     1192                            b->data + pos % BPS(bs), bytes);
    12181193                        rc = block_put(b);
    12191194                        if (rc != EOK) {
     
    12301205
    12311206                assert(nodep->type == FAT_DIRECTORY);
    1232                 assert(nodep->size % bps == 0);
    1233                 assert(bps % sizeof(fat_dentry_t) == 0);
     1207                assert(nodep->size % BPS(bs) == 0);
     1208                assert(BPS(bs) % sizeof(fat_dentry_t) == 0);
    12341209
    12351210                /*
     
    12391214                 * the position pointer accordingly.
    12401215                 */
    1241                 bnum = (pos * sizeof(fat_dentry_t)) / bps;
    1242                 while (bnum < nodep->size / bps) {
     1216                bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs);
     1217                while (bnum < nodep->size / BPS(bs)) {
    12431218                        aoff64_t o;
    12441219
     
    12471222                        if (rc != EOK)
    12481223                                goto err;
    1249                         for (o = pos % (bps / sizeof(fat_dentry_t));
    1250                             o < bps / sizeof(fat_dentry_t);
     1224                        for (o = pos % (BPS(bs) / sizeof(fat_dentry_t));
     1225                            o < BPS(bs) / sizeof(fat_dentry_t);
    12511226                            o++, pos++) {
    12521227                                d = ((fat_dentry_t *)b->data) + o;
     
    13061281        size_t bytes, size;
    13071282        block_t *b;
    1308         uint16_t bps;
    1309         unsigned spc;
    1310         unsigned bpc;           /* bytes per cluster */
    13111283        aoff64_t boundary;
    13121284        int flags = BLOCK_FLAGS_NONE;
     
    13341306
    13351307        bs = block_bb_get(dev_handle);
    1336         bps = uint16_t_le2host(bs->bps);
    1337         spc = bs->spc;
    1338         bpc = bps * spc;
    13391308
    13401309        /*
     
    13451314         * value signalizing a smaller number of bytes written.
    13461315         */
    1347         bytes = min(len, bps - pos % bps);
    1348         if (bytes == bps)
     1316        bytes = min(len, BPS(bs) - pos % BPS(bs));
     1317        if (bytes == BPS(bs))
    13491318                flags |= BLOCK_FLAGS_NOREAD;
    13501319       
    1351         boundary = ROUND_UP(nodep->size, bpc);
     1320        boundary = ROUND_UP(nodep->size, BPC(bs));
    13521321        if (pos < boundary) {
    13531322                /*
     
    13641333                        return;
    13651334                }
    1366                 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);
     1335                rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags);
    13671336                if (rc != EOK) {
    13681337                        (void) fat_node_put(fn);
     
    13711340                        return;
    13721341                }
    1373                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1374                     bytes);
     1342                (void) async_data_write_finalize(callid,
     1343                    b->data + pos % BPS(bs), bytes);
    13751344                b->dirty = true;                /* need to sync block */
    13761345                rc = block_put(b);
     
    13961365                fat_cluster_t mcl, lcl;
    13971366 
    1398                 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
     1367                nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
    13991368                /* create an independent chain of nclsts clusters in all FATs */
    14001369                rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
     
    14151384                        return;
    14161385                }
    1417                 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,
    1418                     flags);
     1386                rc = _fat_block_get(&b, bs, dev_handle, lcl, NULL,
     1387                    (pos / BPS(bs)) % SPC(bs), flags);
    14191388                if (rc != EOK) {
    14201389                        (void) fat_free_clusters(bs, dev_handle, mcl);
     
    14241393                        return;
    14251394                }
    1426                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1427                     bytes);
     1395                (void) async_data_write_finalize(callid,
     1396                    b->data + pos % BPS(bs), bytes);
    14281397                b->dirty = true;                /* need to sync block */
    14291398                rc = block_put(b);
     
    14381407                 * node's cluster chain.
    14391408                 */
    1440                 rc = fat_append_clusters(bs, nodep, mcl);
     1409                rc = fat_append_clusters(bs, nodep, mcl, lcl);
    14411410                if (rc != EOK) {
    14421411                        (void) fat_free_clusters(bs, dev_handle, mcl);
     
    14621431        fat_node_t *nodep;
    14631432        fat_bs_t *bs;
    1464         uint16_t bps;
    1465         uint8_t spc;
    1466         unsigned bpc;   /* bytes per cluster */
    14671433        int rc;
    14681434
     
    14791445
    14801446        bs = block_bb_get(dev_handle);
    1481         bps = uint16_t_le2host(bs->bps);
    1482         spc = bs->spc;
    1483         bpc = bps * spc;
    14841447
    14851448        if (nodep->size == size) {
     
    14911454                 */
    14921455                rc = EINVAL;
    1493         } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
     1456        } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) {
    14941457                /*
    14951458                 * The node will be shrunk, but no clusters will be deallocated.
     
    15091472                        fat_cluster_t lastc;
    15101473                        rc = fat_cluster_walk(bs, dev_handle, nodep->firstc,
    1511                             &lastc, NULL, (size - 1) / bpc);
     1474                            &lastc, NULL, (size - 1) / BPC(bs));
    15121475                        if (rc != EOK)
    15131476                                goto out;
     
    15641527void fat_sync(ipc_callid_t rid, ipc_call_t *request)
    15651528{
    1566         /* Dummy implementation */
    1567         ipc_answer_0(rid, EOK);
     1529        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1530        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1531       
     1532        fs_node_t *fn;
     1533        int rc = fat_node_get(&fn, dev_handle, index);
     1534        if (rc != EOK) {
     1535                ipc_answer_0(rid, rc);
     1536                return;
     1537        }
     1538        if (!fn) {
     1539                ipc_answer_0(rid, ENOENT);
     1540                return;
     1541        }
     1542       
     1543        fat_node_t *nodep = FAT_NODE(fn);
     1544       
     1545        nodep->dirty = true;
     1546        rc = fat_node_sync(nodep);
     1547       
     1548        fat_node_put(fn);
     1549        ipc_answer_0(rid, rc);
    15681550}
    15691551
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r0c61955 r20235a3  
    736736void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request)
    737737{
    738         /* Dummy implementation */
     738        /*
     739         * TMPFS keeps its data structures always consistent,
     740         * thus the sync operation is a no-op.
     741         */
    739742        ipc_answer_0(rid, EOK);
    740743}
  • uspace/srv/hid/console/gcons.c

    r0c61955 r20235a3  
    286286        ssize_t nx = (ssize_t) mouse_x + dx;
    287287        ssize_t ny = (ssize_t) mouse_y + dy;
     288
     289        if (!use_gcons)
     290                return;
    288291       
    289292        mouse_x = (size_t) limit(nx, 0, xres);
  • uspace/srv/hid/fb/fb.c

    r0c61955 r20235a3  
    13471347{
    13481348        mouse_hide();
    1349         pointer_x = x;
    1350         pointer_y = y;
     1349        pointer_x = x % screen.xres;
     1350        pointer_y = y % screen.yres;
    13511351        mouse_show();
    13521352}
  • uspace/srv/hid/kbd/Makefile

    r0c61955 r20235a3  
    5858
    5959ifeq ($(UARCH),arm32)
     60        ifeq ($(MACHINE),gta02)
     61                SOURCES += \
     62                        port/chardev.c \
     63                        ctl/stty.c
     64        endif
    6065        ifeq ($(MACHINE),testarm)
    6166                SOURCES += \
  • uspace/srv/hid/kbd/port/chardev.c

    r0c61955 r20235a3  
    4141#include <kbd.h>
    4242#include <vfs/vfs.h>
     43#include <sys/stat.h>
    4344#include <fcntl.h>
    4445#include <errno.h>
     
    5051#define NAME "kbd"
    5152
     53/** List of devices to try connecting to. */
     54static const char *in_devs[] = {
     55        "/dev/char/ps2a",
     56        "/dev/char/s3c24ser"
     57};
     58
     59static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
     60
    5261int kbd_port_init(void)
    5362{
    54         const char *input = "/dev/char/ps2a";
    5563        int input_fd;
     64        int i;
    5665
    57         printf(NAME ": open %s\n", input);
     66        input_fd = -1;
     67        for (i = 0; i < num_devs; i++) {
     68                struct stat s;
    5869
    59         input_fd = open(input, O_RDONLY);
     70                if (stat(in_devs[i], &s) == EOK)
     71                        break;
     72        }
     73
     74        if (i >= num_devs) {
     75                printf(NAME ": Could not find any suitable input device.\n");
     76                return -1;
     77        }
     78
     79        input_fd = open(in_devs[i], O_RDONLY);
    6080        if (input_fd < 0) {
    61                 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
    62                 return false;
     81                printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
     82                    input_fd);
     83                return -1;
    6384        }
    6485
    6586        dev_phone = fd_phone(input_fd);
    6687        if (dev_phone < 0) {
    67                 printf(NAME ": Failed to connect to device\n");
    68                 return false;
     88                printf(NAME ": Failed connecting to device\n");
     89                return -1;
    6990        }
    7091
     
    7394        if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
    7495                printf(NAME ": Failed to create callback from device\n");
    75                 return false;
     96                return -1;
    7697        }
    7798
  • uspace/srv/vfs/vfs.h

    r0c61955 r20235a3  
    169169
    170170extern int vfs_grab_phone(fs_handle_t);
    171 extern void vfs_release_phone(int);
     171extern void vfs_release_phone(fs_handle_t, int);
    172172
    173173extern fs_handle_t fs_name_to_handle(char *, bool);
  • uspace/srv/vfs/vfs_lookup.c

    r0c61955 r20235a3  
    168168        ipcarg_t rc;
    169169        async_wait_for(req, &rc);
    170         vfs_release_phone(phone);
     170        vfs_release_phone(root->fs_handle, phone);
    171171       
    172172        fibril_mutex_lock(&plb_mutex);
     
    215215        ipcarg_t rc;
    216216        async_wait_for(req, &rc);
    217         vfs_release_phone(phone);
     217        vfs_release_phone(result->triplet.fs_handle, phone);
    218218       
    219219        if (rc == EOK) {
  • uspace/srv/vfs/vfs_node.c

    r0c61955 r20235a3  
    133133                    (ipcarg_t)node->dev_handle, (ipcarg_t)node->index);
    134134                assert(rc == EOK);
    135                 vfs_release_phone(phone);
     135                vfs_release_phone(node->fs_handle, phone);
    136136        }
    137137        if (free_vfs_node)
  • uspace/srv/vfs/vfs_ops.c

    r0c61955 r20235a3  
    131131                        if (rc != EOK) {
    132132                                async_wait_for(msg, NULL);
    133                                 vfs_release_phone(phone);
     133                                vfs_release_phone(fs_handle, phone);
    134134                                fibril_rwlock_write_unlock(&namespace_rwlock);
    135135                                ipc_answer_0(rid, rc);
     
    137137                        }
    138138                        async_wait_for(msg, &rc);
    139                         vfs_release_phone(phone);
     139                        vfs_release_phone(fs_handle, phone);
    140140                       
    141141                        if (rc != EOK) {
     
    196196        if (rc != EOK) {
    197197                async_wait_for(msg, NULL);
    198                 vfs_release_phone(mountee_phone);
    199                 vfs_release_phone(phone);
     198                vfs_release_phone(fs_handle, mountee_phone);
     199                vfs_release_phone(mp_res.triplet.fs_handle, phone);
    200200                /* Mount failed, drop reference to mp_node. */
    201201                if (mp_node)
     
    206206        }
    207207
    208         vfs_release_phone(mountee_phone);
     208        vfs_release_phone(fs_handle, mountee_phone);
    209209       
    210210        /* send the mount options */
     
    212212        if (rc != EOK) {
    213213                async_wait_for(msg, NULL);
    214                 vfs_release_phone(phone);
     214                vfs_release_phone(mp_res.triplet.fs_handle, phone);
    215215                /* Mount failed, drop reference to mp_node. */
    216216                if (mp_node)
     
    221221        }
    222222        async_wait_for(msg, &rc);
    223         vfs_release_phone(phone);
     223        vfs_release_phone(mp_res.triplet.fs_handle, phone);
    224224       
    225225        if (rc == EOK) {
     
    423423                rc = async_req_1_0(phone, VFS_OUT_UNMOUNTED,
    424424                    mr_node->dev_handle);
    425                 vfs_release_phone(phone);
     425                vfs_release_phone(mr_node->fs_handle, phone);
    426426                if (rc != EOK) {
    427427                        fibril_rwlock_write_unlock(&namespace_rwlock);
     
    460460                rc = async_req_2_0(phone, VFS_OUT_UNMOUNT, mp_node->dev_handle,
    461461                    mp_node->index);
    462                 vfs_release_phone(phone);
     462                vfs_release_phone(mp_node->fs_handle, phone);
    463463                if (rc != EOK) {
    464464                        fibril_rwlock_write_unlock(&namespace_rwlock);
     
    716716        async_wait_for(msg, &rc);
    717717       
    718         vfs_release_phone(fs_phone);
     718        vfs_release_phone(file->node->fs_handle, fs_phone);
    719719        fibril_mutex_unlock(&file->lock);
    720720       
     
    747747                async_wait_for(msg, &rc);
    748748               
    749                 vfs_release_phone(fs_phone);
     749                vfs_release_phone(file->node->fs_handle, fs_phone);
    750750                fibril_mutex_unlock(&file->lock);
    751751               
     
    846846        }
    847847       
    848         vfs_release_phone(fs_phone);
     848        vfs_release_phone(file->node->fs_handle, fs_phone);
    849849       
    850850        size_t bytes = IPC_GET_ARG1(answer);
     
    970970        rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t) dev_handle,
    971971            (ipcarg_t) index, LOWER32(size), UPPER32(size));
    972         vfs_release_phone(fs_phone);
     972        vfs_release_phone(fs_handle, fs_phone);
    973973        return (int)rc;
    974974}
     
    10261026        ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    10271027        async_wait_for(msg, &rc);
    1028         vfs_release_phone(fs_phone);
     1028        vfs_release_phone(file->node->fs_handle, fs_phone);
    10291029
    10301030        fibril_mutex_unlock(&file->lock);
     
    10771077        ipcarg_t rv;
    10781078        async_wait_for(msg, &rv);
    1079         vfs_release_phone(fs_phone);
     1079        vfs_release_phone(node->fs_handle, fs_phone);
    10801080
    10811081        ipc_answer_0(rid, rv);
  • uspace/srv/vfs/vfs_register.c

    r0c61955 r20235a3  
    3939#include <ipc/services.h>
    4040#include <async.h>
     41#include <async_rel.h>
    4142#include <fibril.h>
     43#include <fibril_synch.h>
    4244#include <errno.h>
    4345#include <stdio.h>
     
    4648#include <ctype.h>
    4749#include <bool.h>
    48 #include <fibril_synch.h>
    4950#include <adt/list.h>
    5051#include <as.h>
     
    252253int vfs_grab_phone(fs_handle_t handle)
    253254{
     255        link_t *cur;
     256        fs_info_t *fs;
    254257        int phone;
    255258
     
    262265         */
    263266        fibril_mutex_lock(&fs_head_lock);
    264         link_t *cur;
    265         fs_info_t *fs;
    266267        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
    267268                fs = list_get_instance(cur, fs_info_t, fs_link);
     
    269270                        fibril_mutex_unlock(&fs_head_lock);
    270271                        fibril_mutex_lock(&fs->phone_lock);
    271                         phone = ipc_connect_me_to(fs->phone, 0, 0, 0);
     272                        phone = async_relation_create(fs->phone);
    272273                        fibril_mutex_unlock(&fs->phone_lock);
    273274
     
    284285 * @param phone         Phone to FS task.
    285286 */
    286 void vfs_release_phone(int phone)
    287 {
    288         /* TODO: implement connection caching */
    289         ipc_hangup(phone);
     287void vfs_release_phone(fs_handle_t handle, int phone)
     288{
     289        link_t *cur;
     290        fs_info_t *fs;
     291
     292        fibril_mutex_lock(&fs_head_lock);
     293        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     294                fs = list_get_instance(cur, fs_info_t, fs_link);
     295                if (fs->fs_handle == handle) {
     296                        fibril_mutex_unlock(&fs_head_lock);
     297                        fibril_mutex_lock(&fs->phone_lock);
     298                        async_relation_destroy(fs->phone, phone);
     299                        fibril_mutex_unlock(&fs->phone_lock);
     300                        return;
     301                }
     302        }
     303        /* should not really get here */
     304        abort();
     305        fibril_mutex_unlock(&fs_head_lock);
    290306}
    291307
Note: See TracChangeset for help on using the changeset viewer.