Changeset b79d450 in mainline for uspace/srv


Ignore:
Timestamp:
2010-01-27T20:35:49Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb6f1a5
Parents:
fccc236 (diff), 95e6c4f (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/srv
Files:
3 added
33 deleted
46 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/Makefile.common

    rfccc236 rb79d450  
    2828#
    2929
    30 ## Setup toolchain
     30## Common rules for building servers.
    3131#
    3232
    33 include Makefile.common
    34 include $(LIBC_PREFIX)/Makefile.toolchain
    35 include arch/$(UARCH)/Makefile.inc
    36 
    37 CFLAGS += -Iinclude
    38 LINK = arch/$(UARCH)/_link.ld
    39 
    40 ## Sources
     33# Individual makefiles set:
     34#
     35#       USPACE_PREFIX   relative path to uspace/ directory
     36#       LIBS            libraries to link with (with relative path)
     37#       EXTRA_CFLAGS    additional flags to pass to C compiler
     38#       JOB             job file name (like appname.job)
     39#       OUTPUT          output binary name (like appname)
     40#       SOURCES         list of source files
    4141#
    4242
    43 GENERIC_SOURCES = \
    44         main.c \
    45         elf_load.c \
    46         interp.s
     43DEPEND = Makefile.depend
     44DEPEND_PREV = $(DEPEND).prev
    4745
    48 SOURCES := $(GENERIC_SOURCES) $(ARCH_SOURCES)
     46LIBC_PREFIX = $(USPACE_PREFIX)/lib/libc
     47LIBBLOCK_PREFIX = $(USPACE_PREFIX)/lib/libblock
     48LIBFS_PREFIX = $(USPACE_PREFIX)/lib/libfs
     49LIBPCI_PREFIX = $(USPACE_PREFIX)/lib/libpci
     50SOFTINT_PREFIX = $(USPACE_PREFIX)/lib/softint
     51
     52LINK_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
     53
     54JOB = $(OUTPUT).job
     55
    4956OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    5057
    51 .PHONY: all
     58include $(LIBC_PREFIX)/Makefile.toolchain
    5259
    53 all: $(OUTPUT) $(OUTPUT).disasm
     60CFLAGS += $(EXTRA_CFLAGS)
     61
     62.PHONY: all build clean
     63
     64all: \
     65    $(LIBC_PREFIX)/../../../version \
     66    $(LIBC_PREFIX)/../../../Makefile.config \
     67    $(LIBC_PREFIX)/../../../config.h \
     68    $(LIBC_PREFIX)/../../../config.defs \
     69    $(LIBS) \
     70    \
     71    $(OUTPUT) $(OUTPUT).disasm \
     72    $(EXTRA_OUTPUT)
     73        -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
     74
     75clean:
     76        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm $(EXTRA_OUTPUT)
     77        find . -name '*.o' -follow -exec rm \{\} \;
     78
     79build:
    5480
    5581-include $(DEPEND)
     
    5884        $(OBJDUMP) -d $< > $@
    5985
    60 $(OUTPUT): $(OBJECTS) $(LIBS) $(LINK)
    61         $(LD) -T $(LINK) $(LFLAGS) $(OBJECTS) $(LIBS) -o $@ -Map $(OUTPUT).map
    62 
    63 $(LINK): $(LINK).in
    64         $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PREFIX=$(LIBC_PREFIX) -E -x c $< | grep -v "^\#" > $@
     86$(OUTPUT): $(LINK_SCRIPT) $(OBJECTS) $(LIBS)
     87        $(LD) -T $(LINK_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    6588
    6689%.o: %.c $(DEPEND)
     
    7093endif
    7194
    72 %.o: %.s $(DEPEND)
    73         $(AS) $(AFLAGS) $< -o $@
    74 ifeq ($(PRECHECK),y)
    75         $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS)
    76 endif
    77 
    7895$(DEPEND):
    7996        makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
  • uspace/srv/bd/ata_bd/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = ata_bd
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        ata_bd.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../Makefile.common
  • uspace/srv/bd/ata_bd/ata_bd.c

    rfccc236 rb79d450  
    296296                        ipc_answer_1(callid, EOK, block_size);
    297297                        continue;
     298                case BD_GET_NUM_BLOCKS:
     299                        ipc_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
     300                            UPPER32(disk[disk_id].blocks));
     301                        continue;
    298302                default:
    299303                        retval = EINVAL;
  • uspace/srv/bd/file_bd/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = file_bd
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        file_bd.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../Makefile.common
  • uspace/srv/bd/file_bd/file_bd.c

    rfccc236 rb79d450  
    5656
    5757static const size_t block_size = 512;
     58static bn_t num_blocks;
    5859static FILE *img;
    5960
     
    99100{
    100101        int rc;
     102        long img_size;
    101103
    102104        rc = devmap_driver_register(NAME, file_bd_connection);
     
    109111        if (img == NULL)
    110112                return EINVAL;
     113
     114        if (fseek(img, 0, SEEK_END) != 0) {
     115                fclose(img);
     116                return EIO;
     117        }
     118
     119        img_size = ftell(img);
     120        if (img_size < 0) {
     121                fclose(img);
     122                return EIO;
     123        }
     124
     125        num_blocks = img_size / block_size;
    111126
    112127        fibril_mutex_initialize(&dev_lock);
     
    174189                        ipc_answer_1(callid, EOK, block_size);
    175190                        continue;
     191                case BD_GET_NUM_BLOCKS:
     192                        ipc_answer_2(callid, EOK, LOWER32(num_blocks),
     193                            UPPER32(num_blocks));
     194                        continue;
    176195                default:
    177196                        retval = EINVAL;
     
    186205{
    187206        size_t n_rd;
     207        int rc;
    188208
    189209        fibril_mutex_lock(&dev_lock);
    190210
    191         fseek(img, ba * block_size, SEEK_SET);
     211        clearerr(img);
     212        rc = fseek(img, ba * block_size, SEEK_SET);
     213        if (rc < 0) {
     214                fibril_mutex_unlock(&dev_lock);
     215                return EIO;
     216        }
     217
    192218        n_rd = fread(buf, block_size, cnt, img);
    193219
     
    209235{
    210236        size_t n_wr;
     237        int rc;
    211238
    212239        fibril_mutex_lock(&dev_lock);
    213240
    214         fseek(img, ba * block_size, SEEK_SET);
    215         n_wr = fread(buf, block_size, cnt, img);
     241        clearerr(img);
     242        rc = fseek(img, ba * block_size, SEEK_SET);
     243        if (rc < 0) {
     244                fibril_mutex_unlock(&dev_lock);
     245                return EIO;
     246        }
     247
     248        n_wr = fwrite(buf, block_size, cnt, img);
    216249
    217250        if (ferror(img) || n_wr < cnt) {
    218251                fibril_mutex_unlock(&dev_lock);
    219252                return EIO;     /* Write error */
     253        }
     254
     255        if (fflush(img) != 0) {
     256                fibril_mutex_unlock(&dev_lock);
     257                return EIO;
    220258        }
    221259
  • uspace/srv/bd/gxe_bd/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = gxe_bd
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        gxe_bd.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../Makefile.common
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    rfccc236 rb79d450  
    234234                        ipc_answer_1(callid, EOK, block_size);
    235235                        continue;
     236                case BD_GET_NUM_BLOCKS:
     237                        retval = ENOTSUP;
     238                        break;
    236239                default:
    237240                        retval = EINVAL;
  • uspace/srv/bd/part/guid_part/Makefile

    rfccc236 rb79d450  
    11#
    2 # Copyright (c) 2005 Martin Decky
     2# Copyright (c) 2010 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
     29USPACE_PREFIX = ../../../..
     30LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
     31EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
    2932
    30 ## Common names
    31 #
     33# Correct name is 'guid_part' but must use this because of FAT 8.3 names.
     34OUTPUT = g_part
    3235
    33 LIBC_PREFIX = ../../../../lib/libc
    34 SOFTINT_PREFIX = ../../../../lib/softint
    35 LIBBLOCK_PREFIX = ../../../../lib/libblock
    36 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
     36SOURCES = \
     37        guid_part.c
    3738
    38 DEPEND = Makefile.depend
    39 DEPEND_PREV = $(DEPEND).prev
    40 JOB = mbr_part.job
    41 OUTPUT = mbr_part
     39include ../../../Makefile.common
  • uspace/srv/bd/part/mbr_part/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
    3133
    32 .PHONY: all clean
     34OUTPUT = mbr_part
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        mbr_part.c
    3738
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     39include ../../../Makefile.common
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    rfccc236 rb79d450  
    463463                        ipc_answer_1(callid, EOK, block_size);
    464464                        continue;
    465 
     465                case BD_GET_NUM_BLOCKS:
     466                        ipc_answer_2(callid, EOK, LOWER32(part->length),
     467                            UPPER32(part->length));
     468                        continue;
    466469                default:
    467470                        retval = EINVAL;
  • uspace/srv/bd/rd/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = rd
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        rd.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../Makefile.common
  • uspace/srv/bd/rd/rd.c

    rfccc236 rb79d450  
    153153                        ipc_answer_1(callid, EOK, block_size);
    154154                        continue;
     155                case BD_GET_NUM_BLOCKS:
     156                        ipc_answer_2(callid, EOK, LOWER32(rd_size / block_size),
     157                            UPPER32(rd_size / block_size));
     158                        continue;
    155159                default:
    156160                        /*
  • uspace/srv/clip/Makefile

    rfccc236 rb79d450  
    11#
    2 # Copyright (c) 2009 Martin Decky
     2# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 include Makefile.common
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3032
    31 .PHONY: all clean
     33OUTPUT = clip
    3234
    33 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    34         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    35         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        clip.c
    3637
    37 clean:
    38         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    39         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../Makefile.common
  • uspace/srv/devmap/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = devmap
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        devmap.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../Makefile.common
  • uspace/srv/fs/devfs/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS += -I$(LIBFS_PREFIX)
    3133
    32 .PHONY: all clean
     34OUTPUT = devfs
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        devfs.c \
     38        devfs_ops.c
    3739
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     40include ../../Makefile.common
  • uspace/srv/fs/devfs/devfs.c

    rfccc236 rb79d450  
    7575                        devfs_mount(callid, &call);
    7676                        break;
     77                case VFS_OUT_UNMOUNTED:
     78                        devfs_unmounted(callid, &call);
     79                        break;
     80                case VFS_OUT_UNMOUNT:
     81                        devfs_unmount(callid, &call);
     82                        break;
    7783                case VFS_OUT_LOOKUP:
    7884                        devfs_lookup(callid, &call);
  • uspace/srv/fs/devfs/devfs_ops.c

    rfccc236 rb79d450  
    434434}
    435435
     436void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
     437{
     438        ipc_answer_0(rid, ENOTSUP);
     439}
     440
     441void devfs_unmount(ipc_callid_t rid, ipc_call_t *request)
     442{
     443        libfs_unmount(&devfs_libfs_ops, rid, request);
     444}
     445
    436446void devfs_lookup(ipc_callid_t rid, ipc_call_t *request)
    437447{
  • uspace/srv/fs/devfs/devfs_ops.h

    rfccc236 rb79d450  
    4141extern void devfs_mounted(ipc_callid_t, ipc_call_t *);
    4242extern void devfs_mount(ipc_callid_t, ipc_call_t *);
     43extern void devfs_unmounted(ipc_callid_t, ipc_call_t *);
     44extern void devfs_unmount(ipc_callid_t, ipc_call_t *);
    4345extern void devfs_lookup(ipc_callid_t, ipc_call_t *);
    4446extern void devfs_open_node(ipc_callid_t, ipc_call_t *);
  • uspace/srv/fs/fat/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX)
    3133
    32 .PHONY: all clean
     34OUTPUT = fat
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        fat.c \
     38        fat_ops.c \
     39        fat_idx.c \
     40        fat_dentry.c \
     41        fat_fat.c
    3742
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     43include ../../Makefile.common
  • uspace/srv/fs/fat/fat.c

    rfccc236 rb79d450  
    100100                        fat_mount(callid, &call);
    101101                        break;
     102                case VFS_OUT_UNMOUNTED:
     103                        fat_unmounted(callid, &call);
     104                        break;
     105                case VFS_OUT_UNMOUNT:
     106                        fat_unmount(callid, &call);
     107                        break;
    102108                case VFS_OUT_LOOKUP:
    103109                        fat_lookup(callid, &call);
  • uspace/srv/fs/fat/fat.h

    rfccc236 rb79d450  
    204204extern void fat_mounted(ipc_callid_t, ipc_call_t *);
    205205extern void fat_mount(ipc_callid_t, ipc_call_t *);
     206extern void fat_unmounted(ipc_callid_t, ipc_call_t *);
     207extern void fat_unmount(ipc_callid_t, ipc_call_t *);
    206208extern void fat_lookup(ipc_callid_t, ipc_call_t *);
    207209extern void fat_read(ipc_callid_t, ipc_call_t *);
  • uspace/srv/fs/fat/fat_fat.c

    rfccc236 rb79d450  
    247247 */
    248248int
    249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst,
    250     fat_cluster_t *value)
     249fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,
     250    fat_cluster_t clst, fat_cluster_t *value)
    251251{
    252252        block_t *b;
    253253        uint16_t bps;
    254254        uint16_t rscnt;
     255        uint16_t sf;
    255256        fat_cluster_t *cp;
    256257        int rc;
     
    258259        bps = uint16_t_le2host(bs->bps);
    259260        rscnt = uint16_t_le2host(bs->rscnt);
    260 
    261         rc = block_get(&b, dev_handle, rscnt +
     261        sf = uint16_t_le2host(bs->sec_per_fat);
     262
     263        rc = block_get(&b, dev_handle, rscnt + sf * fatno +
    262264            (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
    263265        if (rc != EOK)
     
    398400                         * from the size of the file allocation table.
    399401                         */
    400                         if ((cl - 2) * bs->spc + ssa >= ts) {
     402                        if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) {
    401403                                rc = block_put(blk);
    402404                                if (rc != EOK)
     
    480482        while (firstc < FAT_CLST_LAST1) {
    481483                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    482                 rc = fat_get_cluster(bs, dev_handle, firstc, &nextc);
     484                rc = fat_get_cluster(bs, dev_handle, FAT1, firstc, &nextc);
    483485                if (rc != EOK)
    484486                        return rc;
     
    560562                unsigned fatno;
    561563
    562                 rc = fat_get_cluster(bs, dev_handle, lastc, &nextc);
     564                rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc);
    563565                if (rc != EOK)
    564566                        return rc;
  • uspace/srv/fs/fat/fat_fat.h

    rfccc236 rb79d450  
    8080extern int fat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t,
    8181    fat_cluster_t *, unsigned);
    82 extern int fat_get_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t,
    83     fat_cluster_t *);
     82extern int fat_get_cluster(struct fat_bs *, dev_handle_t, unsigned,
     83    fat_cluster_t, fat_cluster_t *);
    8484extern int fat_set_cluster(struct fat_bs *, dev_handle_t, unsigned,
    8585    fat_cluster_t, fat_cluster_t);
  • uspace/srv/fs/fat/fat_ops.c

    rfccc236 rb79d450  
    290290
    291291        *nodepp = nodep;
     292        return EOK;
     293}
     294
     295/** Perform basic sanity checks on the file system.
     296 *
     297 * Verify if values of boot sector fields are sane. Also verify media
     298 * descriptor. This is used to rule out cases when a device obviously
     299 * does not contain a fat file system.
     300 */
     301static int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle)
     302{
     303        fat_cluster_t e0, e1;
     304        unsigned fat_no;
     305        int rc;
     306
     307        /* Check number of FATs. */
     308        if (bs->fatcnt == 0)
     309                return ENOTSUP;
     310
     311        /* Check total number of sectors. */
     312
     313        if (bs->totsec16 == 0 && bs->totsec32 == 0)
     314                return ENOTSUP;
     315
     316        if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
     317            bs->totsec16 != bs->totsec32)
     318                return ENOTSUP;
     319
     320        /* Check media descriptor. Must be between 0xf0 and 0xff. */
     321        if ((bs->mdesc & 0xf0) != 0xf0)
     322                return ENOTSUP;
     323
     324        /* Check number of sectors per FAT. */
     325        if (bs->sec_per_fat == 0)
     326                return ENOTSUP;
     327
     328        /*
     329         * Check that the root directory entries take up whole blocks.
     330         * This check is rather strict, but it allows us to treat the root
     331         * directory and non-root directories uniformly in some places.
     332         * It can be removed provided that functions such as fat_read() are
     333         * sanitized to support file systems with this property.
     334         */
     335        if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) %
     336            uint16_t_le2host(bs->bps) != 0)
     337                return ENOTSUP;
     338
     339        /* Check signature of each FAT. */
     340
     341        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     342                rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);
     343                if (rc != EOK)
     344                        return EIO;
     345
     346                rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);
     347                if (rc != EOK)
     348                        return EIO;
     349
     350                /* Check that first byte of FAT contains the media descriptor. */
     351                if ((e0 & 0xff) != bs->mdesc)
     352                        return ENOTSUP;
     353
     354                /*
     355                 * Check that remaining bits of the first two entries are
     356                 * set to one.
     357                 */
     358                if ((e0 >> 8) != 0xff || e1 != 0xffff)
     359                        return ENOTSUP;
     360        }
     361
    292362        return EOK;
    293363}
     
    9811051        }
    9821052
     1053        /* Do some simple sanity checks on the file system. */
     1054        rc = fat_sanity_check(bs, dev_handle);
     1055        if (rc != EOK) {
     1056                block_fini(dev_handle);
     1057                ipc_answer_0(rid, rc);
     1058                return;
     1059        }
     1060
    9831061        rc = fat_idx_init_by_dev_handle(dev_handle);
    9841062        if (rc != EOK) {
     
    10371115{
    10381116        libfs_mount(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
     1117}
     1118
     1119void fat_unmounted(ipc_callid_t rid, ipc_call_t *request)
     1120{
     1121        ipc_answer_0(rid, ENOTSUP);
     1122}
     1123
     1124void fat_unmount(ipc_callid_t rid, ipc_call_t *request)
     1125{
     1126        libfs_unmount(&fat_libfs_ops, rid, request);
    10391127}
    10401128
  • uspace/srv/fs/tmpfs/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX)
    3133
    32 .PHONY: all clean
     34OUTPUT = tmpfs
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        tmpfs.c \
     38        tmpfs_ops.c \
     39        tmpfs_dump.c
    3740
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     41include ../../Makefile.common
  • uspace/srv/fs/tmpfs/tmpfs.c

    rfccc236 rb79d450  
    106106                        tmpfs_mount(callid, &call);
    107107                        break;
     108                case VFS_OUT_UNMOUNTED:
     109                        tmpfs_unmounted(callid, &call);
     110                        break;
     111                case VFS_OUT_UNMOUNT:
     112                        tmpfs_unmount(callid, &call);
     113                        break;
    108114                case VFS_OUT_LOOKUP:
    109115                        tmpfs_lookup(callid, &call);
  • uspace/srv/fs/tmpfs/tmpfs.h

    rfccc236 rb79d450  
    8383extern void tmpfs_mounted(ipc_callid_t, ipc_call_t *);
    8484extern void tmpfs_mount(ipc_callid_t, ipc_call_t *);
     85extern void tmpfs_unmounted(ipc_callid_t, ipc_call_t *);
     86extern void tmpfs_unmount(ipc_callid_t, ipc_call_t *);
    8587extern void tmpfs_lookup(ipc_callid_t, ipc_call_t *);
    8688extern void tmpfs_read(ipc_callid_t, ipc_call_t *);
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    rfccc236 rb79d450  
    147147hash_table_t nodes;
    148148
    149 #define NODES_KEY_INDEX 0
    150 #define NODES_KEY_DEV   1
     149#define NODES_KEY_DEV   0       
     150#define NODES_KEY_INDEX 1
    151151
    152152/* Implementation of hash table interface for the nodes hash table. */
     
    160160        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    161161            nh_link);
    162         return (nodep->index == key[NODES_KEY_INDEX] &&
    163             nodep->dev_handle == key[NODES_KEY_DEV]);
     162       
     163        switch (keys) {
     164        case 1:
     165                return (nodep->dev_handle == key[NODES_KEY_DEV]);
     166        case 2:
     167                return ((nodep->dev_handle == key[NODES_KEY_DEV]) &&
     168                    (nodep->index == key[NODES_KEY_INDEX]));
     169        default:
     170                abort();
     171        }
    164172}
    165173
    166174static void nodes_remove_callback(link_t *item)
    167175{
     176        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
     177            nh_link);
     178
     179        while (!list_empty(&nodep->cs_head)) {
     180                tmpfs_dentry_t *dentryp = list_get_instance(nodep->cs_head.next,
     181                    tmpfs_dentry_t, link);
     182
     183                assert(nodep->type == TMPFS_DIRECTORY);
     184                list_remove(&dentryp->link);
     185                free(dentryp);
     186        }
     187
     188        if (nodep->data) {
     189                assert(nodep->type == TMPFS_FILE);
     190                free(nodep->data);
     191        }
     192        free(nodep->bp);
     193        free(nodep);
    168194}
    169195
     
    215241}
    216242
     243static void tmpfs_instance_done(dev_handle_t dev_handle)
     244{
     245        unsigned long key[] = {
     246                [NODES_KEY_DEV] = dev_handle
     247        };
     248        /*
     249         * Here we are making use of one special feature of our hash table
     250         * implementation, which allows to remove more items based on a partial
     251         * key match. In the following, we are going to remove all nodes
     252         * matching our device handle. The nodes_remove_callback() function will
     253         * take care of resource deallocation.
     254         */
     255        hash_table_remove(&nodes, key, 1);
     256}
     257
    217258int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    218259{
     
    237278{
    238279        unsigned long key[] = {
    239                 [NODES_KEY_INDEX] = index,
    240                 [NODES_KEY_DEV] = dev_handle
     280                [NODES_KEY_DEV] = dev_handle,
     281                [NODES_KEY_INDEX] = index
    241282        };
    242283        link_t *lnk = hash_table_find(&nodes, key);
     
    296337        /* Insert the new node into the nodes hash table. */
    297338        unsigned long key[] = {
    298                 [NODES_KEY_INDEX] = nodep->index,
    299                 [NODES_KEY_DEV] = nodep->dev_handle
     339                [NODES_KEY_DEV] = nodep->dev_handle,
     340                [NODES_KEY_INDEX] = nodep->index
    300341        };
    301342        hash_table_insert(&nodes, key, &nodep->nh_link);
     
    312353
    313354        unsigned long key[] = {
    314                 [NODES_KEY_INDEX] = nodep->index,
    315                 [NODES_KEY_DEV] = nodep->dev_handle
     355                [NODES_KEY_DEV] = nodep->dev_handle,
     356                [NODES_KEY_INDEX] = nodep->index
    316357        };
    317358        hash_table_remove(&nodes, key, 2);
    318359
    319         if (nodep->type == TMPFS_FILE)
    320                 free(nodep->data);
    321         free(nodep->bp);
    322         free(nodep);
     360        /*
     361         * The nodes_remove_callback() function takes care of the actual
     362         * resource deallocation.
     363         */
    323364        return EOK;
    324365}
     
    424465        /* Initialize TMPFS instance. */
    425466        if (!tmpfs_instance_init(dev_handle)) {
     467                free(opts);
    426468                ipc_answer_0(rid, ENOMEM);
    427469                return;
     
    442484                    rootp->lnkcnt);
    443485        }
     486        free(opts);
    444487}
    445488
     
    447490{
    448491        libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
     492}
     493
     494void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
     495{
     496        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     497
     498        tmpfs_instance_done(dev_handle);
     499        ipc_answer_0(rid, EOK);
     500}
     501
     502void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request)
     503{
     504        libfs_unmount(&tmpfs_libfs_ops, rid, request);
    449505}
    450506
     
    465521        link_t *hlp;
    466522        unsigned long key[] = {
    467                 [NODES_KEY_INDEX] = index,
    468523                [NODES_KEY_DEV] = dev_handle,
     524                [NODES_KEY_INDEX] = index
    469525        };
    470526        hlp = hash_table_find(&nodes, key);
     
    539595        link_t *hlp;
    540596        unsigned long key[] = {
    541                 [NODES_KEY_INDEX] = index,
    542                 [NODES_KEY_DEV] = dev_handle
     597                [NODES_KEY_DEV] = dev_handle,
     598                [NODES_KEY_INDEX] = index
    543599        };
    544600        hlp = hash_table_find(&nodes, key);
     
    603659        link_t *hlp;
    604660        unsigned long key[] = {
    605                 [NODES_KEY_INDEX] = index,
    606                 [NODES_KEY_DEV] = dev_handle
     661                [NODES_KEY_DEV] = dev_handle,
     662                [NODES_KEY_INDEX] = index
    607663        };
    608664        hlp = hash_table_find(&nodes, key);
     
    646702        link_t *hlp;
    647703        unsigned long key[] = {
    648                 [NODES_KEY_INDEX] = index,
    649                 [NODES_KEY_DEV] = dev_handle
     704                [NODES_KEY_DEV] = dev_handle,
     705                [NODES_KEY_INDEX] = index
    650706        };
    651707        hlp = hash_table_find(&nodes, key);
  • uspace/srv/hid/c_mouse/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS = -Iinclude
    3133
    32 .PHONY: all clean
     34OUTPUT = c_mouse
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        proto/ps2.c \
     38        c_mouse.c \
     39        chardev.c
    3740
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     41include ../../Makefile.common
  • uspace/srv/hw/bus/pci/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../../..
     31LIBS = $(LIBPCI_PREFIX)/libpci.a $(LIBC_PREFIX)/libc.a
     32EXTRA_CFLAGS = -I$(LIBPCI_PREFIX)
    3133
    32 .PHONY: all clean
     34OUTPUT = pci
    3335
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     36SOURCES = \
     37        pci.c
    3738
    38 $(LIBPCI):
    39         $(MAKE) -C libpci PRECHECK=$(PRECHECK)
    40 
    41 clean:
    42         $(MAKE) -C libpci clean
    43         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    44         find . -name '*.o' -follow -exec rm \{\} \;
     39include ../../../Makefile.common
  • uspace/srv/hw/bus/pci/pci.c

    rfccc236 rb79d450  
    2121#include <errno.h>
    2222
    23 #include "libpci/pci.h"
     23#include <pci.h>
    2424
    2525#define PCI_CONF1       0xcf8
  • uspace/srv/hw/char/i8042/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = i8042
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        i8042.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../../Makefile.common
  • uspace/srv/hw/cir/fhc/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = fhc
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        fhc.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../../Makefile.common
  • uspace/srv/hw/cir/obio/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../../../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = obio
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        obio.c
    3737
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     38include ../../../Makefile.common
  • uspace/srv/loader/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30-include ../../../Makefile.config
     31-include arch/$(UARCH)/Makefile.inc
    3132
    32 .PHONY: all clean
     33USPACE_PREFIX = ../..
     34LIBS = $(LIBC_PREFIX)/libc.a
     35EXTRA_CFLAGS += -Iinclude
     36LINK_SCRIPT = arch/$(UARCH)/_link.ld
    3337
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     38OUTPUT = loader
     39EXTRA_OUTPUT = $(LINK_SCRIPT)
    3740
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm arch/*/_link.ld
    40         find . -name '*.o' -follow -exec rm \{\} \;
     41GENERIC_SOURCES = \
     42        main.c \
     43        elf_load.c \
     44        interp.s
     45
     46SOURCES := $(GENERIC_SOURCES) $(ARCH_SOURCES)
     47OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
     48
     49include ../Makefile.common
     50
     51$(LINK_SCRIPT): $(LINK_SCRIPT).in
     52        $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PREFIX=$(LIBC_PREFIX) -E -x c $< | grep -v "^\#" > $@
  • uspace/srv/loader/arch/amd64/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__64_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/amd64.s
  • uspace/srv/loader/arch/arm32/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__32_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/arm32.s
  • uspace/srv/loader/arch/ia32/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__32_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/ia32.s
  • uspace/srv/loader/arch/ia64/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__64_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/ia64.s
    3130AFLAGS += -xexplicit
  • uspace/srv/loader/arch/mips32/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__32_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/mips32.s
  • uspace/srv/loader/arch/ppc32/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__32_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/ppc32.s
  • uspace/srv/loader/arch/sparc64/Makefile.inc

    rfccc236 rb79d450  
    2727#
    2828
    29 CFLAGS += -D__64_BITS__
    3029ARCH_SOURCES := arch/$(UARCH)/sparc64.s
  • uspace/srv/ns/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = ns
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        ns.c \
     37        service.c \
     38        clonable.c \
     39        task.c
    3740
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     41include ../Makefile.common
  • uspace/srv/taskmon/Makefile

    rfccc236 rb79d450  
    11#
    2 # Copyright (c) 2005 Martin Decky
     2# Copyright (c) 2010 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
     29USPACE_PREFIX = ../..
     30LIBS = $(LIBC_PREFIX)/libc.a
    2931
    30 ## Common names
    31 #
     32OUTPUT = taskmon
    3233
    33 LIBC_PREFIX = ../libc
    34 DEPEND = Makefile.depend
    35 DEPEND_PREV = $(DEPEND).prev
    36 JOB = softint.job
    37 LIBSOFTINT = libsoftint.a
     34SOURCES = \
     35        taskmon.c
     36
     37include ../Makefile.common
  • uspace/srv/vfs/Makefile

    rfccc236 rb79d450  
    2828#
    2929
    30 include Makefile.common
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBC_PREFIX)/libc.a
    3132
    32 .PHONY: all clean
     33OUTPUT = vfs
    3334
    34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS)
    35         -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    36         $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
     35SOURCES = \
     36        vfs.c \
     37        vfs_node.c \
     38        vfs_file.c \
     39        vfs_ops.c \
     40        vfs_lookup.c \
     41        vfs_register.c
    3742
    38 clean:
    39         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm
    40         find . -name '*.o' -follow -exec rm \{\} \;
     43include ../Makefile.common
  • uspace/srv/vfs/vfs.c

    rfccc236 rb79d450  
    8686                case VFS_IN_MOUNT:
    8787                        vfs_mount(callid, &call);
     88                        break;
     89                case VFS_IN_UNMOUNT:
     90                        vfs_unmount(callid, &call);
    8891                        break;
    8992                case VFS_IN_OPEN:
  • uspace/srv/vfs/vfs.h

    rfccc236 rb79d450  
    181181extern vfs_node_t *vfs_node_get(vfs_lookup_res_t *);
    182182extern void vfs_node_put(vfs_node_t *);
     183extern void vfs_node_forget(vfs_node_t *);
     184extern unsigned vfs_nodes_refcount_sum_get(fs_handle_t, dev_handle_t);
     185
    183186
    184187#define MAX_OPEN_FILES  128
     
    198201extern void vfs_register(ipc_callid_t, ipc_call_t *);
    199202extern void vfs_mount(ipc_callid_t, ipc_call_t *);
     203extern void vfs_unmount(ipc_callid_t, ipc_call_t *);
    200204extern void vfs_open(ipc_callid_t, ipc_call_t *);
    201205extern void vfs_open_node(ipc_callid_t, ipc_call_t *);
  • uspace/srv/vfs/vfs_node.c

    rfccc236 rb79d450  
    137137        if (free_vfs_node)
    138138                free(node);
     139}
     140
     141/** Forget node.
     142 *
     143 * This function will remove the node from the node hash table and deallocate
     144 * its memory, regardless of the node's reference count.
     145 *
     146 * @param node  Node to be forgotten.
     147 */
     148void vfs_node_forget(vfs_node_t *node)
     149{
     150        fibril_mutex_lock(&nodes_mutex);
     151        unsigned long key[] = {
     152                [KEY_FS_HANDLE] = node->fs_handle,
     153                [KEY_DEV_HANDLE] = node->dev_handle,
     154                [KEY_INDEX] = node->index
     155        };
     156        hash_table_remove(&nodes, key, 3);
     157        fibril_mutex_unlock(&nodes_mutex);
     158        free(node);
    139159}
    140160
     
    231251}
    232252
     253struct refcnt_data {
     254        /** Sum of all reference counts for this file system instance. */
     255        unsigned refcnt;
     256        fs_handle_t fs_handle;
     257        dev_handle_t dev_handle;
     258};
     259
     260static void refcnt_visitor(link_t *item, void *arg)
     261{
     262        vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
     263        struct refcnt_data *rd = (void *) arg;
     264
     265        if ((node->fs_handle == rd->fs_handle) &&
     266            (node->dev_handle == rd->dev_handle))
     267                rd->refcnt += node->refcnt;
     268}
     269
     270unsigned
     271vfs_nodes_refcount_sum_get(fs_handle_t fs_handle, dev_handle_t dev_handle)
     272{
     273        struct refcnt_data rd = {
     274                .refcnt = 0,
     275                .fs_handle = fs_handle,
     276                .dev_handle = dev_handle
     277        };
     278
     279        fibril_mutex_lock(&nodes_mutex);
     280        hash_table_apply(&nodes, refcnt_visitor, &rd);
     281        fibril_mutex_unlock(&nodes_mutex);
     282
     283        return rd.refcnt;
     284}
     285
    233286/**
    234287 * @}
  • uspace/srv/vfs/vfs_ops.c

    rfccc236 rb79d450  
    9292                }
    9393               
    94                 rc = vfs_lookup_internal(mp, L_DIRECTORY, &mp_res, NULL);
     94                rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
    9595                if (rc != EOK) {
    9696                        /* The lookup failed for some reason. */
     
    429429}
    430430
     431void vfs_unmount(ipc_callid_t rid, ipc_call_t *request)
     432{
     433        int rc;
     434        char *mp;
     435        vfs_lookup_res_t mp_res;
     436        vfs_lookup_res_t mr_res;
     437        vfs_node_t *mp_node;
     438        vfs_node_t *mr_node;
     439        int phone;
     440
     441        /*
     442         * Receive the mount point path.
     443         */
     444        rc = async_data_string_receive(&mp, MAX_PATH_LEN);
     445        if (rc != EOK)
     446                ipc_answer_0(rid, rc);
     447
     448        /*
     449         * Taking the namespace lock will do two things for us. First, it will
     450         * prevent races with other lookup operations. Second, it will stop new
     451         * references to already existing VFS nodes and creation of new VFS
     452         * nodes. This is because new references are added as a result of some
     453         * lookup operation or at least of some operation which is protected by
     454         * the namespace lock.
     455         */
     456        fibril_rwlock_write_lock(&namespace_rwlock);
     457       
     458        /*
     459         * Lookup the mounted root and instantiate it.
     460         */
     461        rc = vfs_lookup_internal(mp, L_ROOT, &mr_res, NULL);
     462        if (rc != EOK) {
     463                fibril_rwlock_write_unlock(&namespace_rwlock);
     464                free(mp);
     465                ipc_answer_0(rid, rc);
     466                return;
     467        }
     468        mr_node = vfs_node_get(&mr_res);
     469        if (!mr_node) {
     470                fibril_rwlock_write_unlock(&namespace_rwlock);
     471                free(mp);
     472                ipc_answer_0(rid, ENOMEM);
     473                return;
     474        }
     475
     476        /*
     477         * Count the total number of references for the mounted file system. We
     478         * are expecting at least two. One which we got above and one which we
     479         * got when the file system was mounted. If we find more, it means that
     480         * the file system cannot be gracefully unmounted at the moment because
     481         * someone is working with it.
     482         */
     483        if (vfs_nodes_refcount_sum_get(mr_node->fs_handle,
     484            mr_node->dev_handle) != 2) {
     485                fibril_rwlock_write_unlock(&namespace_rwlock);
     486                vfs_node_put(mr_node);
     487                free(mp);
     488                ipc_answer_0(rid, EBUSY);
     489                return;
     490        }
     491
     492        if (str_cmp(mp, "/") == 0) {
     493
     494                /*
     495                 * Unmounting the root file system.
     496                 *
     497                 * In this case, there is no mount point node and we send
     498                 * VFS_OUT_UNMOUNTED directly to the mounted file system.
     499                 */
     500
     501                free(mp);
     502                phone = vfs_grab_phone(mr_node->fs_handle);
     503                rc = async_req_1_0(phone, VFS_OUT_UNMOUNTED,
     504                    mr_node->dev_handle);
     505                vfs_release_phone(phone);
     506                if (rc != EOK) {
     507                        fibril_rwlock_write_unlock(&namespace_rwlock);
     508                        vfs_node_put(mr_node);
     509                        ipc_answer_0(rid, rc);
     510                        return;
     511                }
     512                rootfs.fs_handle = 0;
     513                rootfs.dev_handle = 0;
     514        } else {
     515
     516                /*
     517                 * Unmounting a non-root file system.
     518                 *
     519                 * We have a regular mount point node representing the parent
     520                 * file system, so we delegate the operation to it.
     521                 */
     522
     523                rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
     524                free(mp);
     525                if (rc != EOK) {
     526                        fibril_rwlock_write_unlock(&namespace_rwlock);
     527                        vfs_node_put(mr_node);
     528                        ipc_answer_0(rid, rc);
     529                        return;
     530                }
     531                vfs_node_t *mp_node = vfs_node_get(&mp_res);
     532                if (!mp_node) {
     533                        fibril_rwlock_write_unlock(&namespace_rwlock);
     534                        vfs_node_put(mr_node);
     535                        ipc_answer_0(rid, ENOMEM);
     536                        return;
     537                }
     538
     539                phone = vfs_grab_phone(mp_node->fs_handle);
     540                rc = async_req_2_0(phone, VFS_OUT_UNMOUNT, mp_node->dev_handle,
     541                    mp_node->index);
     542                vfs_release_phone(phone);
     543                if (rc != EOK) {
     544                        fibril_rwlock_write_unlock(&namespace_rwlock);
     545                        vfs_node_put(mp_node);
     546                        vfs_node_put(mr_node);
     547                        ipc_answer_0(rid, rc);
     548                        return;
     549                }
     550
     551                /* Drop the reference we got above. */
     552                vfs_node_put(mp_node);
     553                /* Drop the reference from when the file system was mounted. */
     554                vfs_node_put(mp_node);
     555        }
     556
     557
     558        /*
     559         * All went well, the mounted file system was successfully unmounted.
     560         * The only thing left is to forget the unmounted root VFS node.
     561         */
     562        vfs_node_forget(mr_node);
     563
     564        fibril_rwlock_write_unlock(&namespace_rwlock);
     565        ipc_answer_0(rid, EOK);
     566}
     567
    431568void vfs_open(ipc_callid_t rid, ipc_call_t *request)
    432569{
     
    454591        /*
    455592         * Make sure that we are called with exactly one of L_FILE and
    456          * L_DIRECTORY. Make sure that the user does not pass L_OPEN.
     593         * L_DIRECTORY. Make sure that the user does not pass L_OPEN,
     594         * L_ROOT or L_MP.
    457595         */
    458596        if (((lflag & (L_FILE | L_DIRECTORY)) == 0) ||
    459597            ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) ||
    460             ((lflag & L_OPEN) != 0)) {
     598            (lflag & (L_OPEN | L_ROOT | L_MP))) {
    461599                ipc_answer_0(rid, EINVAL);
    462600                return;
     
    9001038                }
    9011039                newpos = size + off;
     1040                file->pos = newpos;
    9021041                fibril_mutex_unlock(&file->lock);
    9031042                ipc_answer_1(rid, EOK, newpos);
Note: See TracChangeset for help on using the changeset viewer.