예제 #1
0
파일: rootfs.c 프로젝트: pozdnychev/elfs
telf_status
rootfs_build(telf_ctx *ctx)
{
        telf_status ret;
        telf_obj *root_obj = NULL;
        telf_obj *sections_obj = NULL;
        telf_obj *libs_obj = NULL;
        telf_obj *header_obj = NULL;

        root_obj = elf_obj_new(ctx, "/", NULL,
                               ELF_ROOTDIR,
                               ELF_S_IFDIR);
        if (! root_obj) {
                ERR("root obj creation failed");
                ret = ELF_FAILURE;
                goto err;
        }

        sections_obj = elf_obj_new(ctx, "sections", root_obj,
                                   ELF_SECTION,
                                   ELF_S_IFDIR);
        if (! sections_obj) {
                ERR("section obj creation failed");
                ret = ELF_FAILURE;
                goto err;
        }

        libs_obj = elf_obj_new(ctx, "libs", root_obj,
                               ELF_LIBS,
                               ELF_S_IFDIR);
        if (! libs_obj) {
                ERR("libs obj creation failed");
                ret = ELF_FAILURE;
                goto err;
        }

        header_obj = elf_obj_new(ctx, "header", root_obj,
                                 ELF_HEADER,
                                 ELF_S_IFDIR);
        if (! header_obj) {
                ERR("header obj creation failed");
                ret = ELF_FAILURE;
                goto err;
        }

        list_add(root_obj->entries, sections_obj);
        list_add(root_obj->entries, libs_obj);
        list_add(root_obj->entries, header_obj);

        /* and finally... */
        ctx->root = root_obj;

        ret = ELF_SUCCESS;
  err:
        return ret;
}
예제 #2
0
파일: symentryfs.c 프로젝트: Veejay/elfs
telf_status
symentryfs_build(telf_ctx *ctx,
                 telf_obj *parent)
{
        telf_status ret;
        telf_status rc;
        telf_obj *entry = NULL;
        int i;

        for (i = 0; i < N_ELEMS(symentryfs_fcb); i++) {
                telf_fcb *fcb = symentryfs_fcb + i;

                entry = elf_obj_new(ctx, fcb->str, parent,
                                    ELF_SYMBOL_ENTRY,
                                    ELF_S_IFREG);
                if (! entry) {
                        ERR("can't build entry '%s'", fcb->str);
                        continue;
                }

                entry->free_func = fcb->freecontent_func;
                entry->fill_func = fcb->setcontent_func;

                symentryfs_override_driver(entry->driver);
                list_add(parent->entries, entry);
        }


        ret = ELF_SUCCESS;
  end:
        return ret;
}
예제 #3
0
telf_status
symentryfs_build(telf_ctx *ctx,
                 telf_obj *parent)
{
        telf_obj *entry = NULL;

        for (size_t i = 0; i < N_ELEMS(symentryfs_fcb); i++) {
                telf_fcb *fcb = symentryfs_fcb + i;

                entry = elf_obj_new(ctx, fcb->str, parent,
                                    ELF_SYMBOL_ENTRY,
                                    ELF_S_IFREG);
                if (! entry) {
                        ERR("can't build entry '%s'", fcb->str);
                        continue;
                }

                entry->free_func = fcb->freecontent_func;
                entry->fill_func = fcb->fillcontent_func;

                list_add(parent->entries, entry);
        }


        return ELF_SUCCESS;
}
예제 #4
0
파일: headerfs.c 프로젝트: pozdnychev/elfs
telf_status
headerfs_build(telf_ctx *ctx)
{
        telf_obj *header_obj = NULL;
        telf_status ret;
        telf_status rc;

        rc = elf_namei(ctx, "/header", &header_obj);
        if (ELF_SUCCESS != rc) {
                ERR("can't find '/header' object: %s",
                    elf_status_to_str(rc));
                ret = rc;
                goto end;
        }

        /* now add the pseudo files */
        for (size_t i = 0; i < N_ELEMS(headerfs_fcb); i++) {
                telf_obj *entry = NULL;
                telf_fcb *fcb = headerfs_fcb + i;

                entry = elf_obj_new(ctx, fcb->str, header_obj,
                                    ELF_HEADER_ENTRY,
                                    ELF_S_IFREG);
                if (! entry) {
                        ERR("can't build entry '%s'", fcb->str);
                        continue;
                }

                headerfs_override_driver(entry->driver);
                entry->free_func = fcb->freecontent_func;
                entry->fill_func = fcb->fillcontent_func;

                list_add(header_obj->entries, entry);
        }

        ret = ELF_SUCCESS;
  end:
        return ret;
}
예제 #5
0
파일: libfs.c 프로젝트: Veejay/elfs
telf_status
libfs_build(telf_ctx *ctx)
{
        telf_status ret;
        telf_status rc;
        telf_obj *libfs_obj = NULL;
        telf_obj *entry = NULL;
        int i;
        Elf64_Shdr *shdr = NULL;
        Elf64_Dyn *dyn = NULL;

        /* sanity check */
        rc = elf_namei(ctx, "/libs", &libfs_obj);
        if (ELF_SUCCESS != rc) {
                ERR("can't find '/libfs' object: %s", elf_status_to_str(rc));
                ret = rc;
                goto end;
        }

        shdr = elf_getsectionbytype(ctx, SHT_DYNAMIC);
        if (! shdr) {
                ERR("can't find any SHT_DYNAMIC section");
                ret = ELF_ENOENT;
                goto end;
        }

        /* get all DT_NEEDED strings. */
        for (i = 0; i < shdr->sh_size / sizeof(Elf64_Dyn); i++) {
                telf_obj *entry = NULL;
                char *libname = NULL;

                dyn = (Elf64_Dyn *) (ctx->addr + shdr->sh_offset) + i;

                if (DT_NEEDED != dyn->d_tag)
                        continue;

                libname = strdup(ctx->dstrtab + dyn->d_un.d_val);
                if (! libname) {
                        ERR("strdup(%s): %s", libname, strerror(errno));
                        ret = ELF_ENOMEM;
                        goto end;
                }

                entry = elf_obj_new(ctx, libname, libfs_obj,
                                    ELF_LIBS_ENTRY,
                                    ELF_S_IFLNK);
                if (! entry) {
                        ERR("can't build entry '%s'", libname);
                        continue;
                }

                libfs_override_driver(entry->driver);
                list_add(libfs_obj->entries, entry);
        }

        rc = elf_set_default_libpath(ctx);
        if (ELF_SUCCESS != rc) {
                ERR("Can't set libpath list");
                ret = rc;
                goto end;
        }

        ret = ELF_SUCCESS;
  end:
        return ret;
}