Beispiel #1
0
static void root_init()
{
	ENTER();

    HANDLE_ROOT = dir_create();
    HANDLE_OBJ = dir_create();

    append(HANDLE_ROOT, "obj", HANDLE_OBJ);

    LEAVE();
}
Beispiel #2
0
/* get the file pointer for the nodau config file */
static FILE *config_file(char* mode)
{
	char* f;
	char* xch;
	char* fl;
	FILE *r;

	f = getenv("HOME");
	xch = getenv("XDG_CONFIG_HOME");

	/* use XDG config directory */
	if (!xch || !xch[0]) {
		if (asprintf(&fl,"%s/.config/nodau",f) < 0)
			return NULL;
	}else{
		if (asprintf(&fl,"%s/nodau",xch) < 0)
			return NULL;
	}

	dir_create(fl);

	strcat(fl,"/nodau.conf");

	r = fopen(fl,mode);

	free(fl);

	return r;
}
Beispiel #3
0
/**
 * Handle a "-d<dir>=<path>" option.
 *
 * Sets any of angband's special directories to <path>.
 *
 * The "<path>" can be any legal path for the given system, and should
 * not end in any special path separator (i.e. "/tmp" or "~/.ang-info").
 */
static void change_path(const char *info)
{
	char *info_copy = NULL;
	char *path = NULL;
	char *dir = NULL;
	unsigned int i = 0;
	char dirpath[512];

	if (!info || !info[0])
		quit_fmt("Try '-d<dir>=<path>'.", info);

	info_copy = string_make(info);
	path = strtok(info_copy, "=");
	dir = strtok(NULL, "=");

	for (i = 0; i < N_ELEMENTS(change_path_values); i++) {
		if (my_stricmp(path, change_path_values[i].name) == 0) {
#ifdef SETGID
			if (!change_path_values[i].setgid_ok)
				quit_fmt("Can't redefine path to %s dir on multiuser setup",
						 path);
#endif

			string_free(*change_path_values[i].path);
			*change_path_values[i].path = string_make(dir);

			/* the directory may not exist and may need to be created. */
			path_build(dirpath, sizeof(dirpath), dir, "");
			if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);
			return;
		}
	}

	quit_fmt("Unrecognised -d paramater %s", path);
}
Beispiel #4
0
Datei: dir.c Projekt: mrvn/fstest
Dir *dir_create(Dir *parent, int num) {
    // Allocate directory
    Dir *d = malloc(sizeof(Dir));
    if (d == NULL) {
	perror("dir_create() malloc");
	exit(1);
    }
    list_init(&d->list);
    d->parent = parent;
    d->name[0] = 'd';
    d->name[1] = '0' + num / 10;
    d->name[2] = '0' + num % 10;
    d->name[3] = 0;
    d->num_files = 0;

    // Create directory in filesystem
    //fprintf(stderr, "Creating dir %s\n", dir_path(d));
    if (mkdir(dir_path(d), 0700) != 0) {
	perror(dir_path(d));
	exit(1);
    }

    // Link into dir list and add to active list
    list_add_after(&root_dir.list, &d->list);
    vector_add(active_dirs, d);

    // Create subdirs
    while(--num > 0) {
	(void)dir_create(d, num);
    }

    // All done, return directory
    return d;
}
Beispiel #5
0
dir_t* dir_getDirFromBSON(const bson_t *doc) {
	bson_iter_t iter;
	const bson_value_t *value;
	const char *key;
	dir_t *dir = dir_create();

	if (bson_iter_init(&iter, doc)) {
		while (bson_iter_next(&iter)) {
			key = bson_iter_key(&iter);
			value = bson_iter_value(&iter);

			if (strcmp(key, "_id") == 0) {
				strcpy(dir->id, value->value.v_utf8.str);
			} else if (strcmp(key, "name") == 0) {
				dir->name = strdup(value->value.v_utf8.str);
			} else if (strcmp(key, "parentId") == 0) {
				strcpy(dir->parentId, value->value.v_utf8.str);
			}
			/*
			 if (bson_iter_find(&iter, "_id")) strcpy(dir->id, bson_iter_utf8(&iter, NULL));
			 if (bson_iter_find(&iter, "name")) strcpy(dir->name, bson_iter_utf8(&iter, NULL));
			 if (bson_iter_find(&iter, "parentId")) strcpy(dir->parentId, bson_iter_utf8(&iter, NULL));
			 */
		}
	}

	return dir;
}
Beispiel #6
0
static int moddir_mkdir( INSTANCE * my, int * params )
{
    const char * d = string_get( params[ 0 ] ) ;
    int ret = dir_create( d ) ;
    string_discard( params[ 0 ] ) ;
    return ( ret ) ;
}
Beispiel #7
0
/*! Formats the file system. */
static void do_format(void) {
    printf("Formatting file system...");
    free_map_create();
    if (!dir_create(ROOT_DIR_SECTOR, 16))
        PANIC("root directory creation failed");
    free_map_close();
    printf("done.\n");
}
Beispiel #8
0
/*
 * Create any missing directories. We create only those dirs which may be
 * empty (user/, save/, apex/, info/, help/). The others are assumed 
 * to contain required files and therefore must exist at startup 
 * (edit/, pref/, file/, xtra/).
 *
 * ToDo: Only create the directories when actually writing files.
 */
void create_needed_dirs(void)
{
	char dirpath[512];

	path_build(dirpath, sizeof(dirpath), ANGBAND_DIR_USER, "");
	if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);

	path_build(dirpath, sizeof(dirpath), ANGBAND_DIR_SAVE, "");
	if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);

	path_build(dirpath, sizeof(dirpath), ANGBAND_DIR_APEX, "");
	if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);

	path_build(dirpath, sizeof(dirpath), ANGBAND_DIR_INFO, "");
	if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);

	path_build(dirpath, sizeof(dirpath), ANGBAND_DIR_HELP, "");
	if (!dir_create(dirpath)) quit_fmt("Cannot create '%s'", dirpath);
}
Beispiel #9
0
static int create_config_dir(const char *HOME)
{
   char path[BUFSIZ];

   snprintf(path, sizeof(path), "%s/.config", HOME);

   if (dir_create(path) == -1)
      return -1;

   return 0;
}
Beispiel #10
0
/* Creates directory. True if successful. */
bool 
filesys_mkdir (const char *dir)
{
  bool success = false;

  /*The string *dir cannot be empty.*/
  if (*dir == NULL)
    {
      return success;
    }

  /* Locates the directory where the new directory should be created. */
  struct dir *create_dir;
  char parsed_name[NAME_MAX + 1];
  parse_path (dir, &create_dir, parsed_name);

  block_sector_t sector;
  /*Find a free sector for the directory.*/
  if (!free_map_allocate (1, &sector))
    {
      return success;
    }

  success = dir_create (sector, 16);
  if (!success)
    {
      free_map_release (sector, 1);
      return success;
    }

  success = dir_add (create_dir, parsed_name, sector);
  if (!success)
    {
      free_map_release (sector, 1);
      return success;
    }

  /* Get the dir struct of the directory that is just created and add "." and "..". */
  struct inode *inode = inode_open (sector);
  struct dir *new_dir = dir_open (inode);

  ASSERT (inode != NULL);
  ASSERT (new_dir != NULL);

  dir_add (new_dir, ".", sector);
  dir_add (new_dir, "..", create_dir->inode->sector);
  dir_close (new_dir);
  dir_close (create_dir);

  return success; 
}
Beispiel #11
0
void makeDir(char *dirName) {
	if (!isNull(dirName)) {

		dir_t *dir = dir_create();
		dir->name = strdup(dirName);
		strcpy(dir->parentId, currentDirId);

		if (!filesystem_addDir(dir)) {
			printf("Cannot create directory '%s': Directory or file already exists with that name.\n", dirName);
		}

		dir_free(dir);
	}
}
Beispiel #12
0
/* Formats the file system. */
static void do_format (void)
{
  printf ("Formatting file system...");
  free_map_create ();
  if (!dir_create (ROOT_DIR_SECTOR, 2))
    PANIC ("root directory creation failed");

  if (dir_add(dir_open_root (), ".", ROOT_DIR_SECTOR, true) ==  NULL ||
      dir_add(dir_open_root (), "..", ROOT_DIR_SECTOR, true) == NULL ){
    PANIC ("root directory added . or .. failed");
  }
  
  free_map_close ();
  printf ("done.\n");
}
Beispiel #13
0
/* Formats the file system. */
static void
do_format (void)
{
  struct dir *root_dir = dir_open_root();
  struct inode *root_inode = dir_get_inode(root_dir); 
  printf ("Formatting file system...");
  free_map_create ();
  if (!dir_create (ROOT_DIR_SECTOR, 16))
    PANIC ("root directory creation failed");
  /* add . and .. entry to root directory */
  dir_add(root_dir, ".", inode_get_inumber(root_inode));
  dir_add(root_dir,"..", inode_get_inumber(root_inode));
  free_map_close ();
  printf ("done.\n");
}
Beispiel #14
0
/* Formats the file system. */
static void
do_format (void)
{
  printf ("Formatting file system...");
  free_map_create ();
  if (!dir_create (ROOT_DIR_SECTOR, 16))
    PANIC ("root directory creation failed");
  free_map_close ();

  struct dir *root = dir_open_root ();
  dir_add (root, ".", ROOT_DIR_SECTOR);
  dir_add (root, "..", ROOT_DIR_SECTOR);
  dir_close (root);

  printf ("done.\n");
}
Beispiel #15
0
/* Formats the file system. */
static void
do_format (void)
{
    struct dir *current_dir;
    printf ("Formatting file system...");
    free_map_create ();
    /*Create directory with 2 entries - for . and .. */
    if (!dir_create (ROOT_DIR_SECTOR, 2))
        PANIC ("root directory creation failed");
    free_map_close ();
    /* Create . and .. entries. */
    current_dir = dir_open_root ();
    dir_add (current_dir, ".", ROOT_DIR_SECTOR, false);
    dir_add (current_dir, "..", ROOT_DIR_SECTOR, false);
    dir_close (current_dir);
    printf ("done.\n");
}
Beispiel #16
0
/* create directory file */
bool filesys_create_dir(const char *name)
{
	struct dir *parent_dir;
	struct inode *parent_inode;
	struct inode *tmp;
	struct dir *new_dir;
	bool result = false;
	/* if dir name is NULL, return false*/
	if(name == NULL)
		return result;
	/* copy name to cp_name */
	char *cp_name = malloc( sizeof(char) * (strlen(name)+1) );
	strlcpy(cp_name, name, strlen(name)+1 );
	char *file_name;
	file_name = malloc( sizeof(char) * (strlen(name)+1) );
	if(file_name == NULL)
	{
		free(cp_name);
		return result;
	}
	parent_dir = parse_path(cp_name, file_name);
	/* if already same name file exist in directory, return false*/
	if(dir_lookup(parent_dir, file_name, &tmp) == true)
		return result;
	/* allocate bitmap */
	block_sector_t sector_idx;
	free_map_allocate(1, &sector_idx);
	/* create directory */
	dir_create(sector_idx, 16);
	/* add new entry to parent directory */
	dir_add(parent_dir, file_name, sector_idx);
	/* add entry '.' and '..' to directory */
	new_dir = dir_open( inode_open(sector_idx) ); 
	dir_add(new_dir,".",sector_idx);
	parent_inode = dir_get_inode(parent_dir);
	dir_add(new_dir,"..", inode_get_inumber(parent_inode));

	free(cp_name);
	free(file_name);
	result = true;
	return result;
}
Beispiel #17
0
/*! Creates the directory named dir. Return true if successful, but false
 * if dir already exists or if any directory name in dir, besides the last
 * one does not exist. */
bool _mkdir(const char* dir) {
    /* Inode for the new directory created. */
    struct inode* next_inode;
    
    /* Parent directory. */
    struct dir* cur_dir;
    
    /* Name of the directory. */
    char name[15];
    
    /* Sector number allocated to the new directory. */
    block_sector_t sector;
    
    /* Check the validity of the pointer*/
    if (!checkva(dir))
       exit(-1);
    
    /* The compose the path to a final dir name and its parent directory. */
    if (!decompose_dir(dir, name, &cur_dir)){
        return false;
    }
    ASSERT(cur_dir != NULL);
    
    /* Allocate a new sector for this new directory;
     * Create a new directory */
    if (!free_map_allocate(1, &sector) || 
        !dir_create(sector, 0, dir_get_inode(cur_dir)->sector)){
        
        dir_close(cur_dir);
        return false;
    }
    
    /* Add the new directory to its parent directory. */
    if (!dir_add(cur_dir, name, sector)){
        free_map_release(sector, 1);
        dir_close(cur_dir);
        return false;
    }
    
    dir_close(cur_dir);
    return true;
}
Beispiel #18
0
bool Desktop::create_folder(const char *name) {
	String path = desktop_path();
	path += E_DIR_SEPARATOR;
	path += name;

	if(!dir_create(path.c_str())) {
		alert(_("Unable to create directory '%s'! Please check if directory already exists or you have enough permissions to create it"), path.c_str());
		return false;
	}
	
	DesktopIcon *ic = read_desktop_file(path.c_str(), name);
	if(ic) {
		/* use mouse position so folder icon gets created where was clicked */
		ic->position(last_px, last_py);
		add(ic);
		redraw();
	}
	
	return true;
}
Beispiel #19
0
Datei: dir.c Projekt: mrvn/fstest
void dir_init() {
    list_init(&root_dir.list);
    root_dir.parent = NULL;
    root_dir.name[0] = 0;
    root_dir.num_files = 0;

    // Create directory in filesystem
    //fprintf(stderr, "Creating dir %s\n", root_path);
    if (mkdir(root_path, 0700) != 0) {
	perror(root_path);
	exit(1);
    }

    // Create active vector
    active_dirs = vector_create();
    vector_add(active_dirs, &root_dir);

    // Create subdir
    (void)dir_create(NULL, 1);
}
adv_error advance_fileio_config_load(struct advance_fileio_context* context, adv_conf* cfg_context, struct mame_option* option)
{
	struct fileio_item* i;
	for(i=FILEIO_CONFIG;i->type != FILETYPE_end;++i) {
		/* free a previously loaded value */
		path_free(i->dir_map, i->dir_mac);
		i->dir_map = 0;
		i->dir_mac = 0;

		if (i->config) {
			unsigned j;
			const char* s = conf_string_get_default(cfg_context, i->config);
			const char* a;

			switch (i->mode) {
			case FILEIO_MODE_MULTI : a = file_config_list(s, file_config_dir_multidir, 0); break;
			case FILEIO_MODE_SINGLE : a = file_config_list(s, file_config_dir_singledir, 0); break;
			default: a = s; break;
			}

			log_std(("advance:fileio: %s %s\n", i->config, a));
			path_allocate(&i->dir_map, &i->dir_mac, a);
			for(j=0;j<i->dir_mac;++j)
				dir_create(i->dir_map[j]);
		} else {
			/* add the standard directories search as default */
			path_allocate(&i->dir_map, &i->dir_mac, file_config_dir_singlefile());
		}
	}

#ifdef MESS
	{
		const char* s = conf_string_get_default(cfg_context, "dir_crc");
		const char* a = file_config_list(s, file_config_dir_singledir, 0);
		log_std(("advance:fileio: %s %s\n", "dir_crc", a));
		sncpy(option->crc_dir_buffer, sizeof(option->crc_dir_buffer), a);
	}
#endif

	return 0;
}
Beispiel #21
0
/*
 * Largely stolen from GLib (kudos to the GLib team).
 *
 * This function can be simplified via strtok_r() or stringtok() where
 * tokenizers will normalize cases like "/foo///baz///foo". On other
 * hand, above path is valid to every mkdir() so this is not an issue
 * too much.
 */
bool dir_create_with_parents(const char* name, int perm) {
	E_ASSERT(name != NULL);

	char* fn = strdup(name);
	char* p = fn;

	// skip root if needed
	if(fn[0] == E_DIR_SEPARATOR) {
		p = fn;
		while(*p == E_DIR_SEPARATOR)
			p++;
	} else
		p = fn;

	do {
		while(*p && *p != E_DIR_SEPARATOR)
			p++;
		if(!*p)
			p = NULL;
		else
			*p = '\0';

		/* FIXME: file_test() is needed here; can it be removed? */
		if(!file_test(fn, FILE_TEST_IS_DIR) && !dir_create(fn, perm)) {
			free(fn);
			return false;
		}

		if(p) {
			*p = E_DIR_SEPARATOR;
			p++;

			while(*p && *p == E_DIR_SEPARATOR)
				p++;
		}
	} while(p);

	free(fn);
	return true;
}
Beispiel #22
0
int create_config_dradio_dir()
{
   char *HOME;
   char path[BUFSIZ];

   HOME = getenv("HOME");
   if (!HOME)
   {
      fprintf(stderr, "$HOME not found\n");
      return -1;
   }

   if (create_config_dir(HOME) == -1)
      return -1;

   snprintf(path, sizeof(path), "%s/.config/dradio", HOME);

   if (dir_create(path) == -1)
      return -1;

   return 0;
}
/**
 * Create the default directories.
 */
void advance_fileio_default_dir(void)
{
	struct fileio_item* i;
	for(i=FILEIO_CONFIG;i->type != FILETYPE_end;++i) {
		if (i->config && i->def) {
			const char* def = 0;
			switch (i->mode) {
				case FILEIO_MODE_MULTI : def = file_config_dir_multidir(i->def); break;
				case FILEIO_MODE_SINGLE : def = file_config_dir_singledir(i->def); break;
				case FILEIO_MODE_FILE : def = file_config_dir_singlefile(); break;
			}
			if (def) {
				char** dir_map;
				unsigned dir_mac;
				unsigned j;

				path_allocate(&dir_map, &dir_mac, def);
				for(j=0;j<dir_mac;++j)
					dir_create(dir_map[j]);
				path_free(dir_map, dir_mac);
			}
		}
	}
}
Beispiel #24
0
int main(int argc, char **argv)
{
    if(argc == 1)
    {
        usage();
        exit(1);
    }
    while((cret = getopt(argc,argv,"bwetvf:s:l:u: ")) != EOF) {
        switch(cret) {
        case 'f':	/* Force factor */
            x=atoi(optarg);
            if(x < 0)
                x=1;
            break;
        case 's':	/* Size of files */
            sz=atoi(optarg);
            if(optarg[strlen(optarg)-1]=='k' ||
                    optarg[strlen(optarg)-1]=='K') {
                sz = (1024 * atoi(optarg));
            }
            if(optarg[strlen(optarg)-1]=='m' ||
                    optarg[strlen(optarg)-1]=='M') {
                sz = (1024 * 1024 * atoi(optarg));
            }
            if(sz < 0)
                sz=1;
            break;
        case 'l':	/* lower force value */
            lower=atoi(optarg);
            range=1;
            if(lower < 0)
                lower=1;
            break;
        case 'v':	/* version */
            splash();
            exit(0);
            break;
        case 'u':	/* upper force value */
            upper=atoi(optarg);
            range=1;
            if(upper < 0)
                upper=1;
            break;
        case 't':	/* verbose */
            verbose=1;
            break;
        case 'e':	/* Excel */
            excel=1;
            break;
        case 'b':	/* Best */
            best=1;
            break;
        case 'w':	/* Worst */
            worst=1;
            break;
        }
    }
    mbuffer=(char *)malloc(sz);
    memset(mbuffer,'a',sz);
    if(!excel)
        printf("\nFileop:  File size is %d,  Output is in Ops/sec. (A=Avg, B=Best, W=Worst)\n",sz);
    if(!verbose)
    {
#ifdef Windows
        printf(" .     %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n",
               "mkdir","rmdir","create","read","write","close","stat",
               "access","chmod","readdir","delete"," Total_files");
#else

        printf(" .     %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n",
               "mkdir","rmdir","create","read","write","close","stat",
               "access","chmod","readdir","link  ","unlink","delete",
               " Total_files");
#endif
    }
    if(x==0)
        x=1;
    if(range==0)
        lower=upper=x;
    for(i=lower; i<=upper; i++)
    {
        clear_stats();
        x=i;
        /*
         * Dir Create test
         */
        dir_create(x);

        if(verbose)
        {
            printf("mkdir:   Dirs = %9lld ",stats[_STAT_DIR_CREATE].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_CREATE].total_time);
            printf("         Avg mkdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time,
                   stats[_STAT_DIR_CREATE].total_time/stats[_STAT_DIR_CREATE].counter);
            printf("         Best mkdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_CREATE].best,stats[_STAT_DIR_CREATE].best);
            printf("         Worst mkdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_CREATE].worst,stats[_STAT_DIR_CREATE].worst);
        }
        /*
         * Dir delete test
         */
        dir_delete(x);

        if(verbose)
        {
            printf("rmdir:   Dirs = %9lld ",stats[_STAT_DIR_DELETE].counter);
            printf("Total Time = %12.9f seconds\n",stats[_STAT_DIR_DELETE].total_time);
            printf("         Avg rmdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time,
                   stats[_STAT_DIR_DELETE].total_time/stats[_STAT_DIR_DELETE].counter);
            printf("         Best rmdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_DELETE].best,stats[_STAT_DIR_DELETE].best);
            printf("         Worst rmdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_DELETE].worst,stats[_STAT_DIR_DELETE].worst);
        }

        /*
         * Create test
         */
        file_create(x);
        if(verbose)
        {
            printf("create:  Files = %9lld ",stats[_STAT_CREATE].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_CREATE].total_time);
            printf("         Avg create(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time,
                   stats[_STAT_CREATE].total_time/stats[_STAT_CREATE].counter);
            printf("         Best create(s)/sec   = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_CREATE].best,stats[_STAT_CREATE].best);
            printf("         Worst create(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_CREATE].worst,stats[_STAT_CREATE].worst);
            printf("write:   Files = %9lld ",stats[_STAT_WRITE].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_WRITE].total_time);
            printf("         Avg write(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time,
                   stats[_STAT_WRITE].total_time/stats[_STAT_WRITE].counter);
            printf("         Best write(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_WRITE].best,stats[_STAT_WRITE].best);
            printf("         Worst write(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_WRITE].worst,stats[_STAT_WRITE].worst);
            printf("close:   Files = %9lld ",stats[_STAT_CLOSE].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_CLOSE].total_time);
            printf("         Avg close(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time,
                   stats[_STAT_CLOSE].total_time/stats[_STAT_CLOSE].counter);
            printf("         Best close(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_CLOSE].best,stats[_STAT_CLOSE].best);
            printf("         Worst close(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_CLOSE].worst,stats[_STAT_CLOSE].worst);
        }

        /*
         * Stat test
         */
        file_stat(x);

        if(verbose)
        {
            printf("stat:    Files = %9lld ",stats[_STAT_STAT].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_STAT].total_time);
            printf("         Avg stat(s)/sec      = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time,
                   stats[_STAT_STAT].total_time/stats[_STAT_STAT].counter);
            printf("         Best stat(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_STAT].best,stats[_STAT_STAT].best);
            printf("         Worst stat(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_STAT].worst,stats[_STAT_STAT].worst);
        }
        /*
         * Read test
         */
        file_read(x);

        if(verbose)
        {
            printf("read:    Files = %9lld ",stats[_STAT_READ].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_READ].total_time);
            printf("         Avg read(s)/sec      = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_READ].counter/stats[_STAT_READ].total_time,
                   stats[_STAT_READ].total_time/stats[_STAT_READ].counter);
            printf("         Best read(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_READ].best,stats[_STAT_READ].best);
            printf("         Worst read(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_READ].worst,stats[_STAT_READ].worst);
        }

        /*
         * Access test
         */
        file_access(x);
        if(verbose)
        {
            printf("access:  Files = %9lld ",stats[_STAT_ACCESS].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_ACCESS].total_time);
            printf("         Avg access(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time,
                   stats[_STAT_ACCESS].total_time/stats[_STAT_ACCESS].counter);
            printf("         Best access(s)/sec   = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_ACCESS].best,stats[_STAT_ACCESS].best);
            printf("         Worst access(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_ACCESS].worst,stats[_STAT_ACCESS].worst);
        }
        /*
         * Chmod test
         */
        file_chmod(x);

        if(verbose)
        {
            printf("chmod:   Files = %9lld ",stats[_STAT_CHMOD].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_CHMOD].total_time);
            printf("         Avg chmod(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time,
                   stats[_STAT_CHMOD].total_time/stats[_STAT_CHMOD].counter);
            printf("         Best chmod(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_CHMOD].best,stats[_STAT_CHMOD].best);
            printf("         Worst chmod(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_CHMOD].worst,stats[_STAT_CHMOD].worst);
        }
        /*
         * readdir test
         */
        file_readdir(x);

        if(verbose)
        {
            printf("readdir: Files = %9lld ",stats[_STAT_READDIR].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_READDIR].total_time);
            printf("         Avg readdir(s)/sec   = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time,
                   stats[_STAT_READDIR].total_time/stats[_STAT_READDIR].counter);
            printf("         Best readdir(s)/sec  = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_READDIR].best,stats[_STAT_READDIR].best);
            printf("         Worst readdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_READDIR].worst,stats[_STAT_READDIR].worst);
        }
#if !defined(Windows)
        /*
         * link test
         */
        file_link(x);
        if(verbose)
        {
            printf("link:    Files = %9lld ",stats[_STAT_LINK].counter);
            printf("Total Time = %12.9f seconds\n",stats[_STAT_LINK].total_time);
            printf("         Avg link(s)/sec      = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time,
                   stats[_STAT_LINK].total_time/stats[_STAT_LINK].counter);
            printf("         Best link(s)/sec     = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_LINK].best,stats[_STAT_LINK].best);
            printf("         Worst link(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_LINK].worst,stats[_STAT_LINK].worst);
        }
        /*
         * unlink test
         */
        file_unlink(x);
        if(verbose)
        {
            printf("unlink:  Files = %9lld ",stats[_STAT_UNLINK].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_UNLINK].total_time);
            printf("         Avg unlink(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time,
                   stats[_STAT_UNLINK].total_time/stats[_STAT_UNLINK].counter);
            printf("         Best unlink(s)/sec   = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_UNLINK].best,stats[_STAT_UNLINK].best);
            printf("         Worst unlink(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_UNLINK].worst,stats[_STAT_UNLINK].worst);
        }
#endif
        /*
         * Delete test
         */
        file_delete(x);
        if(verbose)
        {
            printf("delete:  Files = %9lld ",stats[_STAT_DELETE].counter);
            printf("Total Time = %12.9f seconds\n", stats[_STAT_DELETE].total_time);
            printf("         Avg delete(s)/sec    = %12.2f (%12.9f seconds/op)\n",
                   stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time,
                   stats[_STAT_DELETE].total_time/stats[_STAT_DELETE].counter);
            printf("         Best delete(s)/sec   = %12.2f (%12.9f seconds/op)\n",
                   1/stats[_STAT_DELETE].best,stats[_STAT_DELETE].best);
            printf("         Worst delete(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
                   1/stats[_STAT_DELETE].worst,stats[_STAT_DELETE].worst);
        }
        if(!verbose)
        {
            printf("%c %4d %6.0f ",'A',x,stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time);
            printf("%6.0f ",stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time);
            printf("%6.0f ",stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time);
            printf("%6.0f ",stats[_STAT_READ].counter/stats[_STAT_READ].total_time);
            printf("%6.0f ",stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time);
            printf("%6.0f ",stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time);
            printf("%6.0f ",stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time);
            printf("%6.0f ",stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time);
            printf("%6.0f ",stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time);
            printf("%6.0f ",stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time);
#ifndef Windows
            printf("%6.0f ",stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time);
            printf("%6.0f ",stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time);
#endif
            printf("%6.0f ",stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time);
            printf("%12d ",x*x*x);
            printf("\n");
            fflush(stdout);

            if(best)
            {
                printf("%c %4d %6.0f ",'B',x, 1/stats[_STAT_DIR_CREATE].best);
                printf("%6.0f ",1/stats[_STAT_DIR_DELETE].best);
                printf("%6.0f ",1/stats[_STAT_CREATE].best);
                printf("%6.0f ",1/stats[_STAT_READ].best);
                printf("%6.0f ",1/stats[_STAT_WRITE].best);
                printf("%6.0f ",1/stats[_STAT_CLOSE].best);
                printf("%6.0f ",1/stats[_STAT_STAT].best);
                printf("%6.0f ",1/stats[_STAT_ACCESS].best);
                printf("%6.0f ",1/stats[_STAT_CHMOD].best);
                printf("%6.0f ",1/stats[_STAT_READDIR].best);
#ifndef Windows
                printf("%6.0f ",1/stats[_STAT_LINK].best);
                printf("%6.0f ",1/stats[_STAT_UNLINK].best);
#endif
                printf("%6.0f ",1/stats[_STAT_DELETE].best);
                printf("%12d ",x*x*x);
                printf("\n");
                fflush(stdout);
            }
            if(worst)
            {
                printf("%c %4d %6.0f ",'W',x, 1/stats[_STAT_DIR_CREATE].worst);
                printf("%6.0f ",1/stats[_STAT_DIR_DELETE].worst);
                printf("%6.0f ",1/stats[_STAT_CREATE].worst);
                printf("%6.0f ",1/stats[_STAT_READ].worst);
                printf("%6.0f ",1/stats[_STAT_WRITE].worst);
                printf("%6.0f ",1/stats[_STAT_CLOSE].worst);
                printf("%6.0f ",1/stats[_STAT_STAT].worst);
                printf("%6.0f ",1/stats[_STAT_ACCESS].worst);
                printf("%6.0f ",1/stats[_STAT_CHMOD].worst);
                printf("%6.0f ",1/stats[_STAT_READDIR].worst);
#ifndef Windows
                printf("%6.0f ",1/stats[_STAT_LINK].worst);
                printf("%6.0f ",1/stats[_STAT_UNLINK].worst);
#endif
                printf("%6.0f ",1/stats[_STAT_DELETE].worst);
                printf("%12d ",x*x*x);
                printf("\n");
                fflush(stdout);
            }
        }
    }
    return(0);
}
Beispiel #25
0
static void 
_test_dir(void)
{
	if (dir_create("//tmp/test///test1//test2///test3/", 0755))
		printf("create dir failed\n");
}
Beispiel #26
0
/* Creates a file named NAME with the given INITIAL_SIZE.
   Returns true if successful, false otherwise.
   Fails if a file named NAME already exists,
   or if internal memory allocation fails. */
static bool
_filesys_create (const char *full_path, off_t initial_size,
                 bool is_dir)
{
    block_sector_t cwd = thread_current ()->cwd_sector;
    bool found = true;
    if (cwd != (block_sector_t) ROOT_DIR_SECTOR)
    {
        struct inode *curr = NULL;
        curr = inode_open (cwd);
        struct dir *p;
        p = dir_open (inode_open (curr->data.parent_dir_sector));
        struct dir_entry e;
        size_t ofs;
        ASSERT (p != NULL);
        found = false;
        for (ofs = 0;
                inode_read_at (p->inode, &e, sizeof e, ofs) == sizeof e;
                ofs += sizeof e)
        {
            if (e.inode_sector == cwd && e.in_use)
            {
                found = true;
                break;
            }
        }
    }
    if (!found)
        return false;

    char leaf_name[NAME_MAX + 1];
    if (!dir_get_leaf_name (full_path, leaf_name))
        return false;

    struct dir *parent_dir = dir_get_parent_dir (full_path);

    if (parent_dir == NULL)
        return false;

    block_sector_t inode_sector = 0;
    if (!free_map_allocate_one (&inode_sector))
    {
        dir_close (parent_dir);
        return false;
    }
    bool success = is_dir? dir_create (inode_sector, BLOCK_SECTOR_SIZE /
                                       sizeof (struct dir_entry)) :
                   inode_create (inode_sector, initial_size);
    if (!success)
    {
        free_map_release (inode_sector, 1);
        dir_close (parent_dir);
        return false;
    }
    if (!dir_add (parent_dir, leaf_name, inode_sector))
    {
        inode_remove (inode_open (inode_sector));
        free_map_release (inode_sector, 1);
        dir_close (parent_dir);
        return false;
    }
    dir_close (parent_dir);
    return true;
}
Beispiel #27
0
Datei: db.c Projekt: carnil/nodau
/* connect to the database */
int db_connect()
{
    int c;
    char* f;
    char* xdh;
    char* fl;
    error_msg = NULL;

    f = getenv("HOME");
    xdh = getenv("XDG_DATA_HOME");

    /* use XDG data directory for storing the database */
    if (!xdh || !xdh[0]) {
        if (asprintf(&fl,"%s/.local/share/nodau",f) < 0)
            return 1;
    } else {
        if (asprintf(&fl,"%s/nodau",xdh) < 0)
            return 1;
    }

    dir_create(fl);

    if (asprintf(&xdh,"%s/nodau.db",fl) < 0)
        return 1;

    free(fl);
    fl = xdh;

    /* connect */
    c = sqlite3_open_v2(fl, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    free(fl);

    /* check for an error */
    if (c)
        return 1;

    c = db_check();

    /* check for an error */
    if (c)
        return 1;

    /* import from old database file */
    if (!config_read("import_old_db","false")) {
        sqlite3 *odb;
        int i;
        sql_result *res = db_result_alloc();

        if (asprintf(&fl,"%s/.nodau",f) < 0)
            return 1;

        i = sqlite3_open_v2(fl, &odb, SQLITE_OPEN_READWRITE, NULL);
        if (!i) {
            sqlite3_get_table(odb, "SELECT * FROM nodau", &res->data, &res->num_rows, &res->num_cols, &error_msg);
            if (!error_msg) {
                if (res->num_rows) {
                    puts("Importing from old database\n");
                    for (i=0; i<res->num_rows; i++) {
                        db_insert(res->data[OCOLUMN(i,COL_NAME)],res->data[OCOLUMN(i,COL_TEXT)]);
                    }
                }
                db_result_free(res);
            }
        }
        config_write("import_old_db","false");
        free(fl);
    }

    /* check the table exists and return */
    return c;
}
Beispiel #28
0
/* Creates a file named NAME with the given INITIAL_SIZE.
   Returns true if successful, false otherwise.
   Fails if a file named NAME already exists,
   or if internal memory allocation fails. */
bool
filesys_create (const char *name, off_t initial_size, uint32_t is_dir) 
{
  block_sector_t inode_sector = (block_sector_t) -1;
  struct inode *inode = NULL;
  struct dir *search_dir = get_cwd(name);

  if (search_dir == NULL) {
    return false;
  }

  char *part = malloc(NAME_MAX + 1);
  if (part == NULL) {
    return false;
  }
  memset(part, 0, NAME_MAX + 1);
  int retrieved_next_part;
  for (retrieved_next_part = get_next_part(part, &name); retrieved_next_part > 0;
       retrieved_next_part = get_next_part(part, &name)) {
    if (dir_lookup (search_dir, part, &inode)) {
      if (!inode_is_dir(inode)) {
        break;
      } else {
        dir_close(search_dir);
        search_dir = dir_open(inode);
        if (search_dir == NULL) {
          free(part);
          return false;
        }
      }
    } else {
      inode = NULL;
      break;
    }
  }
  if (inode != NULL || get_next_part(part, &name) != 0) {
    if (inode != NULL && !inode_is_dir(inode)) {
      inode_close(inode);
    }
    dir_close(search_dir);
    free(part);
    return false;
  }

  
  bool success = false;
  if (is_dir) {
    block_sector_t parent_sector = inode_get_inumber(dir_get_inode(search_dir));
    success = (search_dir != NULL
               && free_map_allocate (1, &inode_sector)
               && dir_create (inode_sector, initial_size, parent_sector)
               && dir_add (search_dir, part, inode_sector));
  } else {
    success = (search_dir != NULL
               && free_map_allocate (1, &inode_sector)
               && inode_create (inode_sector, initial_size, is_dir)
               && dir_add (search_dir, part, inode_sector));
  }
  
  if (!success) 
    free_map_release (inode_sector, 1);
  dir_close (search_dir);
  free(part);
  return success;
}
Beispiel #29
0
Datei: io.c Projekt: atikinn/EOS
int mkdir (const char *path) {
    if (is_dev(path)) return -1; /* devices can be only opened right now */
    char *dirname = kstrdup(path);
    if (dirname == NULL) return -1; /* ENOMEM */
    return dir_create(cwd, REG, dirname);
}