Exemplo n.º 1
0
int dbg_append(char* name)
{
    int x=0;
    int size, fd, rc;
    char tmp[CHUNKSIZE+1];

    fd = open(name,O_RDONLY);
    if (fd<0) {
        DEBUGF("Failed opening file\n");
        return -1;
    }

    size = lseek(fd, 0, SEEK_END);
    DEBUGF("File is %d bytes\n", size);
    x = size / CHUNKSIZE;
    LDEBUGF("Check base is %x (%d)\n",x,size);

    if (close(fd) < 0)
        return -1;

    fd = open(name,O_RDWR|O_APPEND);
    if (fd<0) {
        DEBUGF("Failed opening file\n");
        return -1;
    }

    sprintf(tmp,"%c%06x,",name[1],x++);
    rc = write(fd, tmp, 8);
    if ( rc < 0 )
        panicf("Failed writing data\n");

    return close(fd);
}
Exemplo n.º 2
0
void SegmentationImpl::computeSolution()
{
    if (!datatermAvailable()) {
        LDEBUGF("No dataterm available. Cannot compute solution.");
        return;
    }

    if (!weightAvailable()) {
        LDEBUGF("No weight available. Cannot compute solution.");
        return;
    }

    tvsolver()->computeSolution(dataterm(), weight(), settings()->numLabels(), feedback_.get());
    if (tvsolver()->solutionAvailable()) {
        LINFOF("Computed solution");
    } else {
        LWARNINGF("Failed to compute solution.");
    }
}
Exemplo n.º 3
0
int dbg_chkfile(char* name, int size)
{
    char text[81920];
    int i;
    int x=0;
    int pos = 0;
    int block=0;
    int fd = open(name,O_RDONLY);
    if (fd<0) {
        DEBUGF("Failed opening file\n");
        return -1;
    }

    size = lseek(fd, 0, SEEK_END);
    DEBUGF("File is %d bytes\n", size);
    /* random start position */
    if ( size )
        pos = ((int)rand() % size) & ~7;
    lseek(fd, pos, SEEK_SET);
    x = pos / CHUNKSIZE;

    LDEBUGF("Check base is %x (%d)\n",x,pos);

    while (1) {
        int rc = read(fd, text, sizeof text);
        DEBUGF("read %d bytes\n",rc);
        if (rc < 0) {
            panicf("Failed reading data\n");
        }
        else {
            char tmp[CHUNKSIZE+1];
            if (!rc)
                break;
            for (i=0; i<rc/CHUNKSIZE; i++ ) {
                sprintf(tmp,"%c%06x,",name[1],x++);
                if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) {
                    int idx = pos + block*sizeof(text) + i*CHUNKSIZE;
                    DEBUGF("Mismatch in byte 0x%x (byte 0x%x of sector 0x%x)."
                           "\nExpected %.8s found %.8s\n",
                           idx, idx % SECTOR_SIZE, idx / SECTOR_SIZE,
                           tmp,
                           text+i*CHUNKSIZE);
                    DEBUGF("i=%x, idx=%x\n",i,idx);
                    dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40, idx - 0x20);
                    return -1;
                }
            }
        }
        block++;
    }
    
    return close(fd);
}
Exemplo n.º 4
0
int dbg_mkfile(char* name, int num)
{
    char text[BUFSIZE+1];
    int i;
    int fd;
    int x=0;
    bool stop = false;

    fd = creat(name,O_WRONLY);
    if (fd<0) {
        DEBUGF("Failed creating file\n");
        return -1;
    }
    num *= 1024;
    while ( num ) {
        int rc;
        int len = num > BUFSIZE ? BUFSIZE : num;

        for (i=0; i<len/CHUNKSIZE; i++ )
            sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++);

        rc = write(fd, text, len);
        if ( rc < 0 ) {
            DEBUGF("Failed writing data\n");
            return -1;
        }
        else
            if ( rc == 0 ) {
                DEBUGF("No space left\n");
                return -2;
            }
            else
                DEBUGF("wrote %d bytes\n",rc);

        num -= len;

        if ( !num ) {
            if ( stop )
                break;

            /* add a random number of chunks to test byte-copy code */
            num = ((int) rand() % SECTOR_SIZE) & ~7;
            LDEBUGF("Adding random size %d\n",num);
            stop = true;
        }
    }

    return close(fd);
}
Exemplo n.º 5
0
void SegmentationImpl::computeVisualization()
{
    if (!solutionAvailable()) {
        LDEBUGF("No solution available. Cannot compute visualization.");
        return;
    }

    if (!inputImageColorAvailable()) {
        LDEBUGF("No inputImageColor available. Cannot compute visualization.");
        return;
    }

    if (!labelsAvailable()) {
        LDEBUGF("No labels available. Cannot compute visualization.");
        return;
    }

    tvvisualizer()->computeVisualization(solution(), inputImageGroundTruth(), inputImageColor(), labels(), settings()->numLabels(), feedback_.get());
    if (tvvisualizer()->visualizationAvailable()) {
        LINFOF("Computed visualization");
    } else {
        LWARNINGF("Failed to compute visualization.");
    }
}
Exemplo n.º 6
0
void SegmentationImpl::computeKMeans()
{
    const int n = settings()->numLabels();

    if (!inputImageColorAvailable()) {
        LDEBUGF("No image available; Cannot compute %d means", n);
        return;
    }

    kmeans()->computeMeans(inputImageColor(), n);
    if (kmeans()->maxNumMeans() >= n) {
        LINFOF("Computed %d means successfully", n);
    } else {
        LWARNINGF("Failed to compute %d means", n);
    }
}
Exemplo n.º 7
0
void SegmentationImpl::computeDataterm()
{
    if (!inputImageColorAvailable()) {
        LDEBUGF("No image available. Cannot compute dataterm.");
        return;
    }

    tvdataterm()->computeDataterm(inputImageColor(),
                                  inputImageDepth(),
                                  inputSettings()->intrinsics(),
                                  scribbles(),
                                  settings()->numLabels(),
                                  feedback_.get());
    if (tvdataterm()->datatermAvailable()) {
        LINFOF("Computed dataterm");
    } else {
        LWARNINGF("Failed to compute dataterm.");
    }
}
Exemplo n.º 8
0
static int open_internal(const char* pathname, int flags, bool use_cache)
{
    DIR_UNCACHED* dir;
    struct dirent_uncached* entry;
    int fd;
    char pathnamecopy[MAX_PATH];
    char* name;
    struct filedesc* file = NULL;
    int rc;
#ifndef HAVE_DIRCACHE
    (void)use_cache;
#endif

    LDEBUGF("open(\"%s\",%d)\n",pathname,flags);

    if ( pathname[0] != '/' ) {
        DEBUGF("'%s' is not an absolute path.\n",pathname);
        DEBUGF("Only absolute pathnames supported at the moment\n");
        errno = EINVAL;
        return -1;
    }

    /* find a free file descriptor */
    for ( fd=0; fd<MAX_OPEN_FILES; fd++ )
        if ( !openfiles[fd].busy )
            break;

    if ( fd == MAX_OPEN_FILES ) {
        DEBUGF("Too many files open\n");
        errno = EMFILE;
        return -2;
    }

    file = &openfiles[fd];
    memset(file, 0, sizeof(struct filedesc));

    if (flags & (O_RDWR | O_WRONLY)) {
        file->write = true;

        if (flags & O_TRUNC)
            file->trunc = true;
    }
    file->busy = true;

#ifdef HAVE_DIRCACHE
    if (dircache_is_enabled() && !file->write && use_cache)
    {
        const struct dircache_entry *ce;
# ifdef HAVE_MULTIVOLUME
        int volume = strip_volume(pathname, pathnamecopy);
# endif

        ce = dircache_get_entry_ptr(pathname);
        if (!ce)
        {
            errno = ENOENT;
            file->busy = false;
            return -7;
        }

        fat_open(IF_MV2(volume,)
                 ce->startcluster,
                 &(file->fatfile),
                 NULL);
        file->size = ce->size;
        file->attr = ce->attribute;
        file->cacheoffset = -1;
        file->fileoffset = 0;

        return fd;
    }
#endif

    strlcpy(pathnamecopy, pathname, sizeof(pathnamecopy));

    /* locate filename */
    name=strrchr(pathnamecopy+1,'/');
    if ( name ) {
        *name = 0; 
        dir = opendir_uncached(pathnamecopy);
        *name = '/';
        name++;
    }
    else {
        dir = opendir_uncached("/");
        name = pathnamecopy+1;
    }
    if (!dir) {
        DEBUGF("Failed opening dir\n");
        errno = EIO;
        file->busy = false;
        return -4;
    }

    if(name[0] == 0) {
        DEBUGF("Empty file name\n");
        errno = EINVAL;
        file->busy = false;
        closedir_uncached(dir);
        return -5;
    }

    /* scan dir for name */
    while ((entry = readdir_uncached(dir))) {
        if ( !strcasecmp(name, entry->d_name) ) {
            fat_open(IF_MV2(dir->fatdir.file.volume,)
                     entry->startcluster,
                     &(file->fatfile),
                     &(dir->fatdir));
            file->size = file->trunc ? 0 : entry->size;
            file->attr = entry->attribute;
            break;
        }
    }
Exemplo n.º 9
0
int open(const char* pathname, int flags)
{
    DIR* dir;
    struct dirent* entry;
    int fd;
    char pathnamecopy[MAX_PATH];
    char* name;
    struct filedesc* file = NULL;
    int rc;

    LDEBUGF("open(\"%s\",%d)\n",pathname,flags);

    if ( pathname[0] != '/' ) {
        DEBUGF("'%s' is not an absolute path.\n",pathname);
        DEBUGF("Only absolute pathnames supported at the moment\n");
        errno = EINVAL;
        return -1;
    }

    /* find a free file descriptor */
    for ( fd=0; fd<MAX_OPEN_FILES; fd++ )
        if ( !openfiles[fd].busy )
            break;

    if ( fd == MAX_OPEN_FILES ) {
        DEBUGF("Too many files open\n");
        errno = EMFILE;
        return -2;
    }

    file = &openfiles[fd];
    memset(file, 0, sizeof(struct filedesc));

    if (flags & (O_RDWR | O_WRONLY)) {
        file->write = true;

        if (flags & O_TRUNC)
            file->trunc = true;
    }
    file->busy = true;

    strncpy(pathnamecopy,pathname,sizeof(pathnamecopy));
    pathnamecopy[sizeof(pathnamecopy)-1] = 0;

    /* locate filename */
    name=strrchr(pathnamecopy+1,'/');
    if ( name ) {
        *name = 0; 
        dir = opendir(pathnamecopy);
        *name = '/';
        name++;
    }
    else {
        dir = opendir("/");
        name = pathnamecopy+1;
    }
    if (!dir) {
        DEBUGF("Failed opening dir\n");
        errno = EIO;
        file->busy = false;
        return -4;
    }

    if(name[0] == 0) {
        DEBUGF("Empty file name\n");
        errno = EINVAL;
        file->busy = false;
        closedir(dir);
        return -5;
    }
    
    /* scan dir for name */
    while ((entry = readdir(dir))) {
        if ( !strcasecmp(name, entry->d_name) ) {
            fat_open(IF_MV2(dir->fatdir.file.volume,)
                     entry->startcluster,
                     &(file->fatfile),
                     &(dir->fatdir));
            file->size = file->trunc ? 0 : entry->size;
            file->attr = entry->attribute;
            break;
        }
    }