Example #1
0
pSourceList add_file_to_opkList(char* longname,char* filename,pLocation location,Sint64 version,char* description,char* long_description)
{
	pAlias alias = aliasList;
	while (alias)
	{
		if (strcmp(alias->alias_name,longname) == 0)
			break;
		alias = alias->next;
	}
	char* test;
	if (alias)
		test = alias->name;
	else
		test = longname;
	//Searching in the opkList
	pOpkList file = opkList;
	while (file)
	{
		if (strcmp(file->longName,test) == 0)
			break;
		file = file->next;
	}
	if (file) //found
		return add_new_source(file,location,filename,version,description,long_description);
	return add_new_file(test,filename,location,version,description,long_description);
}
Example #2
0
int tagfs_link(const char *file, const char *tags){
  LOGCALL();

  char **tagsbuf;
  comm_getTags(tags, &tagsbuf);
  char **tmp = tagsbuf;
  int cpt = 0, i;

  while(tmp != NULL && strcmp(file + 1, *tmp) != 0){
    tmp++;
    cpt++;
  }

  if(*tmp == NULL || *(tmp + 1) != NULL){
    comm_freeTags(tagsbuf);
    return FAILURE;
  }

  if (!exist_file(db, file + 1))
	add_new_file(db, file + 1);
  for(i = 0; i < cpt; ++i)
    add_tag_to_file(db, file + 1, tagsbuf[i]);

  comm_freeTags(tagsbuf);
  return SUCCESS;
}
Example #3
0
/*  device table entries take the form of:
    <path>	<type> <mode>	<uid>	<gid>	<major>	<minor>	<start>	<inc>	<count>
    /dev/mem    c      640      0       0       1       1       0        0        -

    type can be one of: 
	f	A regular file
	d	Directory
	c	Character special device file
	b	Block special device file
	p	Fifo (named pipe)

    I don't bother with symlinks (permissions are irrelevant), hard
    links (special cases of regular files), or sockets (why bother).

    Regular files must exist in the target root directory.  If a char,
    block, fifo, or directory does not exist, it will be created.
*/
static int interpret_table_entry(char *line)
{
	char *name;
	char path[4096], type;
	unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
	unsigned long start = 0, increment = 1, count = 0;

	if (0 > sscanf(line, "%40s %c %lo %lu %lu %lu %lu %lu %lu %lu", path,
		    &type, &mode, &uid, &gid, &major, &minor, &start,
		    &increment, &count)) 
	{
		return 1;
	}

	if (!strcmp(path, "/")) {
		error_msg_and_die("Device table entries require absolute paths");
	}
	name = xstrdup(path+1);
	sprintf(path, "%s/%s\0", rootdir, name);

	switch (type) {
	case 'd':
		mode |= S_IFDIR;
		add_new_directory(name, path, uid, gid, mode);
		break;
	case 'f':
		mode |= S_IFREG;
		add_new_file(name, path, uid, gid, mode);
		break;
	case 'p':
		mode |= S_IFIFO;
		add_new_fifo(name, path, uid, gid, mode);
		break;
	case 'c':
	case 'b':
		mode |= (type == 'c') ? S_IFCHR : S_IFBLK;
		if (count > 0) {
			int i;
			dev_t rdev;
			char buf[80];

			for (i = start; i < start+count; i++) {
				sprintf(buf, "%s%d", name, i);
				rdev = makedev(major, minor + (i * increment - start));
				add_new_device(buf, path, uid, gid, mode, rdev);
			}
		} else {
			dev_t rdev = makedev(major, minor);

			add_new_device(name, path, uid, gid, mode, rdev);
		}
		break;
	default:
		error_msg_and_die("Unsupported file type");
	}
	if (name) free(name);
	return 0;
}
Example #4
0
static t_file	*move_to_file(const int fd, t_file **myfile)
{
	t_file	*fptr;

	fptr = *myfile;
	while (fptr)
	{
		if (fd == fptr->fd)
			return (fptr);
		fptr = fptr->next;
	}
	fptr = add_new_file(fd);
	fptr->next = *myfile;
	*myfile = fptr;
	return (fptr);
}
Example #5
0
/*
 * Find all symbols in filename that are exported with EXPORT_SYMBOL &
 * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly).
 * All symbols located are stored in symfilelist.
 */
static void find_export_symbols(char * filename)
{
	FILE * fp;
	struct symfile *sym;
	char line[MAXLINESZ];
	if (filename_exist(filename) == NULL) {
		char real_filename[PATH_MAX + 1];
		memset(real_filename, 0, sizeof(real_filename));
		strncat(real_filename, srctree, PATH_MAX);
		strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
		strncat(real_filename, filename,
				PATH_MAX - strlen(real_filename));
		sym = add_new_file(filename);
		fp = fopen(real_filename, "r");
		if (fp == NULL)
		{
			fprintf(stderr, "docproc: ");
			perror(real_filename);
			exit(1);
		}
		while (fgets(line, MAXLINESZ, fp)) {
			char *p;
			char *e;
			if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) ||
                            ((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) {
				/* Skip EXPORT_SYMBOL{_GPL} */
				while (isalnum(*p) || *p == '_')
					p++;
				/* Remove parentheses & additional whitespace */
				while (isspace(*p))
					p++;
				if (*p != '(')
					continue; /* Syntax error? */
				else
					p++;
				while (isspace(*p))
					p++;
				e = p;
				while (isalnum(*e) || *e == '_')
					e++;
				*e = '\0';
				add_new_symbol(sym, p);
			}
		}
		fclose(fp);
	}
}
Example #6
0
/*
 * Find all symbols exported with EXPORT_SYMBOL and EXPORT_SYMBOL_GPL
 * in filename.
 * All symbols located are stored in symfilelist.
 */
void find_export_symbols(char * filename)
{
	FILE * fp;
	struct symfile *sym;
	char line[MAXLINESZ];
	if (filename_exist(filename) == NULL) {
		int rflen = strlen(getenv("SRCTREE")) + strlen(filename);
		char *real_filename = alloca(rflen + 1);
		strcpy(real_filename, getenv("SRCTREE"));
		strcat(real_filename, filename);
		sym = add_new_file(filename);
		fp = fopen(real_filename, "r");
		if (fp == NULL)
		{
			fprintf(stderr, "docproc: ");
			perror(real_filename);
		}
		while (fgets(line, MAXLINESZ, fp)) {
			char *p;
			char *e;
			if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != 0) ||
			    ((p = strstr(line, "EXPORT_SYMBOL")) != 0)) {
				/* Skip EXPORT_SYMBOL{_GPL} */
				while (isalnum(*p) || *p == '_')
					p++;
				/* Remove paranteses and additional ws */
				while (isspace(*p))
					p++;
				if (*p != '(')
					continue; /* Syntax error? */
				else
					p++;
				while (isspace(*p))
					p++;
				e = p;
				while (isalnum(*e) || *e == '_')
					e++;
				*e = '\0';
				add_new_symbol(sym, p);
			}
		}
		fclose(fp);
	}
}
Example #7
0
/*  device table entries take the form of:
    <path>	<type> <mode>	<uid>	<gid>	<major>	<minor>	<start>	<inc>	<count>
    /dev/mem    c      640      0       0       1       1       0        0        -

    type can be one of: 
	f	A regular file
	d	Directory
	c	Character special device file
	b	Block special device file
	p	Fifo (named pipe)

    I don't bother with symlinks (permissions are irrelevant), hard
    links (special cases of regular files), or sockets (why bother).

    Regular files must exist in the target root directory.  If a char,
    block, fifo, or directory does not exist, it will be created.

    count can be prepended with an 'h' to indicate the numbers to append must be hex.
    I.e. if start, inc and count are 0,1,h12 respectively the devices will be appended with
    0,1,2....9,a,b and not 0,1,2....9,10,11 which is the case if 'h' is omitted
*/
static int interpret_table_entry(char *line)
{
	char *name;
	char path[4096], type;
	unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
	unsigned long start = 0, increment = 1, count = 0;
	char countstr[20+1];
	char*pcountstr = countstr;
	int do_hex = 0;

	if (0 > sscanf(line, "%40s %c %lo %lu %lu %lu %lu %lu %lu %20s", path,
		    &type, &mode, &uid, &gid, &major, &minor, &start,
		    &increment, countstr)) 
	{
		return 1;
	}

	if (countstr[0] == 'h') {
		pcountstr++;
		do_hex = 1;
	}
	sscanf(pcountstr,"%lu", &count);
	
	if (!strcmp(path, "/")) {
		error_msg_and_die("Device table entries require absolute paths");
	}
	name = xstrdup(path + 1);
	sprintf(path, "%s/%s\0", rootdir, name);

	switch (type) {
	case 'd':
		mode |= S_IFDIR;
		add_new_directory(name, path, uid, gid, mode);
		break;
	case 'f':
		mode |= S_IFREG;
		add_new_file(name, path, uid, gid, mode);
		break;
	case 'p':
		mode |= S_IFIFO;
		add_new_fifo(name, path, uid, gid, mode);
		break;
	case 'c':
	case 'b':
		mode |= (type == 'c') ? S_IFCHR : S_IFBLK;
		if (count > 0) {
			int i;
			dev_t rdev;
			char buf[80];

			for (i = start; i < count; i++) {
				if (do_hex) {
					sprintf(buf, "%s%x", name, i);
				} else {
					sprintf(buf, "%s%d", name, i);
				}
				/* FIXME:  MKDEV uses illicit insider knowledge of kernel 
				 * major/minor representation...  */
				rdev = MKDEV(major, minor + (i * increment - start));
				add_new_device(buf, path, uid, gid, mode, rdev);
			}
		} else {
			/* FIXME:  MKDEV uses illicit insider knowledge of kernel 
			 * major/minor representation...  */
			dev_t rdev = MKDEV(major, minor);

			add_new_device(name, path, uid, gid, mode, rdev);
		}
		break;
	default:
		error_msg_and_die("Unsupported file type");
	}
	if (name) free(name);
	return 0;
}
Example #8
0
/*  device table entries take the form of:
    <path>	<type> <mode>	<usr>	<grp>	<major>	<minor>	<start>	<inc>	<count>
    /dev/mem    c      640      0       0       1       1       0        0        -
    /dev/zero   c      644      root    root    1       5       -        -        -

    type can be one of:
	f	A regular file
	d	Directory
	c	Character special device file
	b	Block special device file
	p	Fifo (named pipe)

    I don't bother with symlinks (permissions are irrelevant), hard
    links (special cases of regular files), or sockets (why bother).

    Regular files must exist in the target root directory.  If a char,
    block, fifo, or directory does not exist, it will be created.
*/
static int interpret_table_entry(char *line)
{
	char *name;
	char usr_buf[MAX_ID_LEN];
	char grp_buf[MAX_ID_LEN];
	char path[4096], type;
	unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
	unsigned long start = 0, increment = 1, count = 0;

	if (0 > sscanf(line, "%4095s %c %lo %40s %40s %lu %lu %lu %lu %lu", path,
		    &type, &mode, usr_buf, grp_buf, &major, &minor, &start,
		    &increment, &count))
	{
		fprintf(stderr, "%s: sscanf returned < 0 for line '%s'\n", app_name, line);
		return 1;
	}

	uid = convert2guid(usr_buf, usr_list);
	gid = convert2guid(grp_buf, grp_list);

	if (strncmp(path, "/", 1)) {
		error_msg_and_die("Device table entries require absolute paths");
	}
	name = xstrdup(path + 1);
	/* prefix path with rootdir */
	sprintf(path, "%s/%s", rootdir, name);

	/* XXX Why is name passed into all of the add_new_*() routines? */
	switch (type) {
	case 'd':
		mode |= S_IFDIR;
		add_new_directory(name, path, uid, gid, mode);
		break;
	case 'f':
		mode |= S_IFREG;
		add_new_file(name, path, uid, gid, mode);
		break;
	case 'p':
		mode |= S_IFIFO;
		add_new_fifo(name, path, uid, gid, mode);
		break;
	case 'c':
	case 'b':
		mode |= (type == 'c') ? S_IFCHR : S_IFBLK;
		if (count > 0) {
			int i;
			dev_t rdev;
			char buf[80];

			for (i = start; i < start + count; i++) {
				sprintf(buf, "%s%d", name, i);
				sprintf(path, "%s/%s%d", rootdir, name, i);
				/* FIXME:  MKDEV uses illicit insider knowledge of kernel
				 * major/minor representation...  */
				rdev = MKDEV(major, minor + (i - start) * increment);
				sprintf(path, "%s/%s\0", rootdir, buf);
				add_new_device(buf, path, uid, gid, mode, rdev);
			}
		} else {
			/* FIXME:  MKDEV uses illicit insider knowledge of kernel
			 * major/minor representation...  */
			dev_t rdev = MKDEV(major, minor);
			add_new_device(name, path, uid, gid, mode, rdev);
		}
		break;
	default:
		error_msg_and_die("Unsupported file type");
	}
	if (name) free(name);
	return 0;
}
Example #9
0
static void recursive_add_directory(char *dname)
{
	DIR *dir;
	char path[BUFSIZ];
	struct dirent *dp;
	struct stat sb;
	struct directory_entry *parent;


	sprintf(path, "%s", dname);

	if (lstat(path, &sb)) {
		perror_msg_and_die("%s", path);
	}

	parent =
		add_new_directory(dname, path, sb.st_uid, sb.st_gid, sb.st_mode);
	dir = opendir(path);
	if (!dir) {
		perror_msg_and_die("opening directory %s", path);
	}
	while ((dp = readdir(dir))) {

		if (dp->d_name[0] == '.' && (dp->d_name[1] == 0 || 
			    (dp->d_name[1] == '.' && dp->d_name[2] == 0))) {
			continue;
		}
		if (strcmp(dname, ".") == 0)
			sprintf(path, "%s", dp->d_name);
		else
			sprintf(path, "%s/%s", dname, dp->d_name);
		if (lstat(path, &sb)) {
			perror_msg_and_die("%s", path);
		}

		switch (sb.st_mode & S_IFMT) {
		case S_IFDIR:
			recursive_add_directory(path);
			break;

		case S_IFREG:
		case S_IFSOCK:
		case S_IFIFO:
		case S_IFLNK:
			add_new_file(dp->d_name, path, sb.st_uid, sb.st_gid,
						 sb.st_mode, parent);
			break;
		case S_IFCHR:
		case S_IFBLK:
			add_new_device(dp->d_name, path, sb.st_uid, sb.st_gid,
						   sb.st_mode, sb.st_rdev, parent);
			break;

		default:
			error_msg("Unknown file type %o for %s", sb.st_mode, path);
			break;
		}
	}

	closedir(dir);
}