Пример #1
0
KFS_EXTERN rc_t KQuickMountDirMake (const KDirectory * self, 
                                    const KDirectory ** pnewdir,
                                    const KFile * file,
                                    const char * path, size_t path_size,
                                    const char * mount, size_t mount_size)
{
    KQuickMountDir * newdir;
    char * pc;
    rc_t rc;
    bool endslash;
    char tbuff [8193];

    endslash = path[path_size-1] == '/';

    if (sizeof tbuff - 1 < mount_size)
        return RC (rcFS, rcDirectory, rcCreating, rcBuffer, rcInsufficient);

    memcpy (tbuff, mount, mount_size);
    tbuff[mount_size] = '\0';

    while ((pc = strpbrk (tbuff, "\"\\/")) != NULL)
        *pc = '_';

    rc = KFileAddRef (file);
    if (rc == 0)
    {
        newdir = KQuickMountDirAlloc (path_size, mount_size);
        if (newdir == NULL)
            rc = RC (rcFS, rcDirectory, rcAllocating, rcMemory, rcExhausted);
        else
        {
            newdir->file = file;
            newdir->mount = newdir->path + path_size;
            rc = KQuickMountDirMakePath (newdir, rcCreating, true, newdir->path,
                                         path_size + 1 + mount_size + 1,
                                         endslash?"%s%s":"%s/%s", path, tbuff);
            if (rc == 0)
            {
                rc = KDirectoryInit (&newdir->dad, (const KDirectory_vt*) &vtKQuickMountDir,
                                     "KQuickMountDir", path?path:"(null)", false);
                if (rc == 0)
                {
                    newdir->mount = newdir->path + path_size + 1;
                    newdir->root = 0;
                    *pnewdir = &newdir->dad;
                    return 0;
                }
/*             rc = RC (rcFS, rcDirectory, rcInitializing, rcObject, rcInvalid); */
            }
            KQuickMountDirDestroy (newdir);
        }
    }
    return rc;
}
Пример #2
0
static
rc_t KDirectoryMakeSraNodeDir (const KDirectory ** pself, const KFile * file,
                               const char * name)
{
    CCNodeSraDir * self;
    size_t name_size;
    rc_t rc;

    assert (pself);

    name_size = string_size (name);
    self = malloc (sizeof (*self) + name_size + 1);
    if (self == NULL)
        rc = RC (rcExe, rcNoTarg, rcAllocating, rcMemory, rcExhausted);
    else
    {
        rc = KFileAddRef (file);
        if (rc == 0)
        {
            rc_t orc;
            self->file = file;
            self->dir_name = root_name;
            self->sub_name = (const char *)(self+1);
            self->name_size = name_size;
            strcpy ((char*)self->sub_name, name);
            rc = KDirectoryInit (&self->dad, (const KDirectory_vt*)&CCNodeSraDir_vt,
                                 "CCSraNodeDir", root_name, false);
            if (rc == 0)
            {
                *pself = &self->dad;
                return 0;
            }
            orc = KFileRelease (file);
            if (orc)
            {
                PLOGERR (klogErr,
                         (klogErr, orc,
                          "Error releaseing sub file '$(F) in a KAR archive",
                          "F=%s", name));
                if (rc == 0)
                    rc = orc;
            }
        }
    }
    return rc;
}