示例#1
0
文件: xfsutil.c 项目: brkt/fuse-xfs
int find_path(xfs_mount_t *mp, const char *path, xfs_inode_t **result) {
    xfs_inode_t *current;
    xfs_ino_t inode;
    struct xfs_name xname;
    int error;
   
    error = libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &current, 0);
    assert(error==0);
    
    xname = first_name(path);
    while (xname.len != 0) {
        if (!(current->i_d.di_mode & S_IFDIR)) {
            libxfs_iput(current, 0);
            return XFS_ERROR(ENOTDIR);
        }
        
        error = libxfs_dir_lookup(NULL, current, &xname, &inode, NULL);
        if (error != 0) {
            return error;
        }

        /* Done with current: make it available */
        libxfs_iput(current, 0);

        error = libxfs_iget(mp, NULL, inode, 0, &current, 0);
        if (error != 0) {
            printf("Failed to get inode for %s %d\n", xname.name, xname.len);
            return XFS_ERROR(EIO);
        }
        xname = next_name(xname);
    }
    *result = current;
    return 0;
}
示例#2
0
static int parse_end_sequence(struct TestFile *tf, const char *kind,
                              const char *name, size_t name_len)
{
    char message[32] = "end ";
    char *tok;
    size_t len;

    strncpy(message + 4, kind, sizeof(message) - 4);
    if (expect_token(tf, "end", message))
        return -1;
    // expect kind
    tok = next_token(tf, &len);
    assert(tok != NULL);
    if (tok == END_OF_LINE) {
        syntax_error(tf);
        return -1;
    }
    if (!same_token(kind, strlen(kind), tok, len)) {
        vfail(tf, tf->read_pos, "expected \"end %s\"", kind);
        return -1;
    }
    // check end name if given and present
    if (name) {
        tok = next_name(tf, &len);
        assert(tok != NULL);
        if (tok != END_OF_LINE && !same_token(name, name_len, tok, len)) {
            vfail(tf, tf->read_pos, "mismatched %s name", kind);
            return -1;
        }
    }
    return expect_eol(tf);
}
示例#3
0
文件: scmd.c 项目: sabrown256/pactnew
static source_record *mk_source_record(double time, double *ldata)
   {source_record *sp;

    sp       = CMAKE(source_record);
    sp->time = time;
    sp->name = next_name();
    sp->data = ldata;

    return(sp);}
示例#4
0
static char *expect_name(struct TestFile *tf, size_t *len, const char *kind)
{
    char *name = next_name(tf, len);
    if (!name || name == END_OF_LINE) {
        vfail(tf, tf->read_pos, "expected %s name", kind);
        return NULL;
    }
    return name;
}
示例#5
0
static void
wrapper(void (*cb)(void))
{
	gboolean rc = FALSE;
	GError *err = NULL;

	g_printerr("\n");
	hc_url_set(url, HCURL_REFERENCE, next_name("container"));
	hc_url_set(url, HCURL_PATH, next_name("content"));
	g_debug("ROUND with [%s] %s", hc_url_get(url, HCURL_HEXID),
			hc_url_get(url, HCURL_WHOLE));

	rc = meta2_remote_container_create(&addr, timeout, &err, hc_url_get_id(url),
			hc_url_get(url, HCURL_REFERENCE));
	CHECK_RC_ERR(rc, err, "CREATE");

	if (cb)
		cb();
}
示例#6
0
文件: opt.c 项目: amboar/iviewiir
static const char *next_opt(const char *p, unsigned *i, unsigned *len)
{
	for (; *i < opt_count; (*i)++) {
		if (opt_table[*i].type == OPT_SUBTABLE)
			continue;
		if (!p)
			return first_name(opt_table[*i].names, len);
		p = next_name(p, len);
		if (p)
			return p;
	}
	return NULL;
}
示例#7
0
文件: xfsutil.c 项目: brkt/fuse-xfs
struct xfs_name first_name(const char *path) {
    struct xfs_name name;
    
    if (!path) {
        name.name = NULL;
        name.len = 0;
        return name;
    }
    
    name.name = path;
    name.len = 0;
    return next_name(name);
}
示例#8
0
/*
 * Essentially, find the conflict reported in check_collisions() and remove
 * it from the second name, unless that happens to be the last alias.
 */
static bool
remove_collision(char *n1, char *n2)
{
    char *p1 = n1;
    char *p2 = n2;
    char *pstart, *qstart, *pend, *qend;
    bool removed = FALSE;

#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
    if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
	p1 = n1 = skip_index(n1);
	p2 = n2 = skip_index(n2);
    }
#else
    (void) p1;
#endif

    for (pstart = n1; (pend = name_ending(pstart)); pstart = next_name(pend)) {
	for (qstart = n2; (qend = name_ending(qstart)); qstart = next_name(qend)) {
	    if ((pend - pstart == qend - qstart)
		&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
		if (qstart != p2 || *qend == '|') {
		    if (*qend == '|')
			++qend;
		    while ((*qstart++ = *qend++) != '\0') ;
		    fprintf(stderr, "...now\t%s\n", p2);
		} else {
		    fprintf(stderr, "Cannot remove alias '%.*s'\n",
			    (int) (qend - qstart), qstart);
		}
		removed = TRUE;
		break;
	    }
	}
    }

    return removed;
}
示例#9
0
文件: opt.c 项目: cdecker/lightning
static void check_opt(const struct opt_table *entry)
{
	const char *p;
	unsigned len;

	if (entry->type != OPT_HASARG && entry->type != OPT_NOARG
	    && entry->type != (OPT_EARLY|OPT_HASARG)
	    && entry->type != (OPT_EARLY|OPT_NOARG))
		failmsg("Option %s: unknown entry type %u",
			entry->names, entry->type);

	if (!entry->desc)
		failmsg("Option %s: description cannot be NULL", entry->names);


	if (entry->names[0] != '-')
		failmsg("Option %s: does not begin with '-'", entry->names);

	for (p = first_name(entry->names, &len); p; p = next_name(p, &len)) {
		if (*p == '-') {
			if (len == 1)
				failmsg("Option %s: invalid long option '--'",
					entry->names);
			opt_num_long++;
		} else {
			if (len != 1)
				failmsg("Option %s: invalid short option"
					" '%.*s'", entry->names, len+1, p-1);
			opt_num_short++;
			if (entry->type == OPT_HASARG)
				opt_num_short_arg++;
		}
		/* Don't document args unless there are some. */
		if (entry->type == OPT_NOARG) {
			if (p[len] == ' ' || p[len] == '=')
				failmsg("Option %s: does not take arguments"
					" '%s'", entry->names, p+len+1);
		}
	}
}
示例#10
0
/*
** Open a port
*/
static ErlDrvData trace_file_start(ErlDrvPort port, char *buff)
{
    unsigned size, cnt, time, tail, len;
    char *p;
    TraceFileData     *data;
    TraceFileWrapData *wrap;
    FILETYPE fd;
    int n, w;
    static const char name[] = "trace_file_drv";

#ifdef HARDDEBUG
    fprintf(stderr,"hello (%s)\r\n", buff);
#endif
    w = 0; /* Index of where sscanf gave up */
    size = 0; /* Warning elimination */
    cnt = 0;  /* -""- */
    time = 0;  /* -""- */
    tail = 0; /* -""- */
    n = sscanf(buff, "trace_file_drv %n w %u %u %u %u %n",
               &w, &size, &cnt, &time, &tail, &w);

    if (w < sizeof(name) || (n != 0 && n != 4))
        return ERL_DRV_ERROR_BADARG;

    /* Search for "n <Filename>" in the rest of the string */
    p = buff + w;
    for (p = buff + w; *p == ' '; p++); /* Skip space (necessary?) */
    if (*p++ != 'n')
        return ERL_DRV_ERROR_BADARG;
    if (*p++ != ' ')
        return ERL_DRV_ERROR_BADARG;
    /* Here we are at the start of the filename; p */
    len = strlen(p);
    if (tail >= len)
        /* Tail must start within filename */
        return ERL_DRV_ERROR_BADARG;

    data = my_alloc(sizeof(TraceFileData) - 1 + BUFFER_SIZE);

    /* We have to check the length in case we are running on
     * VxWorks since too long pathnames may cause bus errors
     * instead of error return from file operations.
     */
    if (n == 4) {
        /* Size limited wrapping log */
        unsigned d = digits(cnt); /* Nof digits in filename counter */
        if (len+d >= MAXPATHLEN) {
            errno = ENAMETOOLONG;
            return ERL_DRV_ERROR_ERRNO;
        }
        wrap = my_alloc(sizeof(TraceFileWrapData));
        wrap->size = size;
        wrap->cnt = cnt;
        wrap->time = time;
        wrap->len = 0;
        strcpy(wrap->cur.name, p);
        wrap->cur.suffix = tail;
        wrap->cur.tail = tail;
        wrap->cur.len = len;
        wrap->cur.cnt = cnt;
        wrap->cur.n = cnt;
        next_name(&wrap->cur); /* Incr to suffix "0" */
        wrap->del = wrap->cur; /* Struct copy! */
        p = wrap->cur.name; /* Use new name for open */
    } else {
        /* Regular log */
        if (len >= MAXPATHLEN) {
            errno = ENAMETOOLONG;
            return ERL_DRV_ERROR_ERRNO;
        }
        wrap = NULL;
    }

    if ((fd = open(p, O_WRONLY | O_TRUNC | O_CREAT
#ifdef O_BINARY
                   | O_BINARY
#endif
                   , 0777)) < 0) {
        if (wrap)
            driver_free(wrap);
        driver_free(data);
        return ERL_DRV_ERROR_ERRNO;
    }

    data->fd = fd;
    data->port = port;
    data->buff_siz = BUFFER_SIZE;
    data->buff_pos = 0;
    data->wrap = wrap;

    if (first_data) {
        data->prev = first_data->prev;
        first_data->prev = data;
    } else
        data->prev = NULL;
    data->next = first_data;
    first_data = data;

    if (wrap && wrap->time > 0)
        driver_set_timer(port, wrap->time);

    return (ErlDrvData) data;
}