static void max_file_size(void) { add_dir( FOUND, ""); add_file( FOUND, "a", 1); add_file( FOUND, "b", 2); add_file(NOT_FOUND, "c", 3); add_dir ( FOUND, "d"); snprintf(extra_config, sizeof(extra_config), "include=%s\nmax_file_size=2", fullpath); }
static void exclude_dir(void) { add_dir( FOUND, ""); add_file( FOUND, "a", 1); add_dir (NOT_FOUND, "d"); add_file(NOT_FOUND, "d/x", 1); add_file( FOUND, "e", 3); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "exclude=%s/d\n", fullpath, fullpath); }
static void exclude_extension(void) { add_dir( FOUND, ""); add_file(NOT_FOUND, "a.c", 1); add_file(NOT_FOUND, "a.h", 2); add_file( FOUND, "b", 2); add_file( FOUND, "b.x", 2); add_file(NOT_FOUND, "c.c", 3); add_dir ( FOUND, "d"); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "exclude_ext=c\n" "exclude_ext=h\n", fullpath); }
GList * category_group_list_get (void) { GList *category_groups = NULL; GSList *dir_list = NULL, *sl; GList *categories, *l; FormatTemplateCategoryGroup *current_group; add_dir (&dir_list, gnm_conf_get_autoformat_sys_dir (), gnm_sys_data_dir ()); add_dir (&dir_list, gnm_conf_get_autoformat_usr_dir (), gnm_usr_dir (FALSE)); add_dir (&dir_list, gnm_conf_get_autoformat_usr_dir (), gnm_usr_dir (TRUE)); for (sl = gnm_conf_get_autoformat_extra_dirs (); sl; sl = sl->next) { const char *dir = sl->data; add_dir (&dir_list, dir, g_get_home_dir ()); } dir_list = g_slist_reverse (dir_list); categories = category_list_get_from_dir_list (dir_list); go_slist_free_custom (dir_list, g_free); categories = g_list_sort (categories, category_compare_name_and_dir); current_group = NULL; for (l = categories; l != NULL; l = l->next) { FormatTemplateCategory *category = l->data; if (current_group == NULL || strcmp (current_group->name, category->name) != 0) { if (current_group != NULL) { category_groups = g_list_prepend (category_groups, current_group); } current_group = g_new (FormatTemplateCategoryGroup, 1); current_group->categories = g_list_append (NULL, category); current_group->name = g_strdup (category->name); current_group->description = g_strdup (category->description); } else { current_group->categories = g_list_prepend (current_group->categories, category); } } if (current_group != NULL) category_groups = g_list_prepend (category_groups, current_group); g_list_free (categories); return category_groups; }
static void simple_entries(void) { add_dir( FOUND, ""); add_file(FOUND, "a", 1); add_file(FOUND, "b", 2); add_file(FOUND, "c", 3); add_dir (FOUND, "d"); add_slnk(FOUND, "e", "a"); add_hlnk(FOUND, "f", "a"); add_hlnk(FOUND, "g", "a"); add_fifo_special(FOUND, "h"); add_sock(FOUND, "i"); snprintf(extra_config, sizeof(extra_config), "include=%s", fullpath); }
static void exclude_regex(void) { add_dir( FOUND, ""); add_file( FOUND, "a", 1); add_file( FOUND, "b", 1); add_file( FOUND, "c", 1); add_file(NOT_FOUND, "dnotthisone", 1); add_dir ( FOUND, "e"); add_dir (NOT_FOUND, "e/fexc"); add_file(NOT_FOUND, "fnotthisone", 1); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "exclude_regex=not\n" "exclude_regex=exc\n", fullpath); }
int main(int argc, char *argv[]) { struct direct *sp; static char cwd[PATH_MAX]; //if (sizeof(struct dinode) != 4096) { // dprintf(2, "sizeof(struct dinode) %d != 4096\n", sizeof(struct dinode)); // return -1; //} if (argc != 3) { dprintf(2, "Usage: mkfs fs rootdir\n"); return -1; } if ((disk = open(argv[1], O_RDWR | O_CREAT | O_TRUNC)) < 0) { dprintf(2, "open(%s) failed\n", argv[1]); return -1; } if ((int)(sp = (struct direct *) sbrk(16*1024*1024)) == -1) { dprintf(2, "sbrk() failed\n"); return -1; } // write zero bitmap write_disk(buf, BUFSZ); // populate file system getcwd(cwd, sizeof(cwd)); chdir(argv[2]); add_dir(bn = 16, sp); chdir(cwd); // update bitmap memset(buf, 0xff, bn / 8); if (bn & 7) buf[bn / 8] = (1 << (bn & 7)) - 1; lseek(disk, 0, SEEK_SET); write_disk(buf, (bn + 7) / 8); close(disk); return 0; }
static int hello_mkdir(const char* path, mode_t mode) { struct simple_directory *d = create_directory(path, S_IFDIR | mode); add_dir(root_directory, d); return 0; }
return_type fsOpenDir(const int nparams, arg_type *a) { if (nparams != 1) { r.return_val = set_error(EINVAL); r.return_size = sizeof(int); r.in_error = 1; return r; } char * serverFolder = append_local_path(a->arg_val); DIR * dir = opendir(serverFolder); if (dir == NULL) { r.return_val = set_error(ENOTDIR); r.return_size = sizeof(int); r.in_error = 1; } else { int * id = malloc(sizeof(int)); *id = add_dir(dir); r.return_val = (void *) id; r.return_size = sizeof(int); r.in_error = 0; } free(serverFolder); return r; }
Error PathMan::read_dir(const char * path) { uint32_t len = strlen(path); char word[len+1]; memcpy(word, path, len); word[len ] = 0; char * ppath[] = {word, 0}; LookUp lu = lookup("/"), flu; if (lu.err) return lu.err; FTSENT *node; FTS *tree = fts_open(ppath, FTS_NOCHDIR, 0); if (!tree) return FAILURE; { size_t len; while ((node = fts_read(tree))) { char word[node->fts_pathlen + 3]; if (node->fts_info & FTS_F) { mkword(node, word, len); flu = add_file(word, 0); if (flu.err) goto fout; flu.file->offset = 0; flu.file->size = node->fts_statp->st_size; } else if (node->fts_info & FTS_D) { mkword(node, word, len); if (len > 1) { if (word[len - 1] != '/') { word[len++] = '/'; } word[len] = 0; lu = add_dir(word, 0); if (lu.err) goto dout; } } } fts_close(tree); } return SUCCESS; fout: fts_close(tree); return flu.err; dout: fts_close(tree); return lu.err; }
void check_live() { coord_s opentile[boardmaxw * boardmaxh]; int n; int i, j; int x, y; int x1, y1; int tilecount = 0; int livecount; n = 2; opentile[0].x = sourcex; opentile[1].x = sourcex; opentile[0].y = sourceytop; opentile[1].y = sourceybottom; for (i=0; i<boardw; i++) { for (j=0; j<boardh; j++) { if (board[i][j]) tilecount++; board[i][j] &= ~16; } } board[sourcex][sourceytop] |= 16; board[sourcex][sourceybottom] |= 16; livecount = 2; while (n) { n--; x = opentile[n].x; y = opentile[n].y; for (j=0; j<4; j++) { if (board[x][y] & (1 << j)) { add_dir(&x1, &y1, x, y, j); if (x1 < 0 || x1 >= boardw || y1 < 0 || y1 >= boardh) { continue; } i = board[x1][y1]; if (i & (1 << ((j + 2) % 4))) { if (!(i & 16)) { board[x1][y1] |= 16; livecount++; opentile[n].x = x1; opentile[n].y = y1; n++; } } } } } if (livecount == tilecount) { game_won = 1; } }
static void fifo_all(void) { add_dir( FOUND, ""); add_fifo( FOUND, "a"); add_fifo( FOUND, "b"); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "read_all_fifos=1\n", fullpath); }
static int add_dir_wrapper(const char *fpath, const struct stat *sp, int tf, struct FTW *pfwt) { char *new_path = malloc( strlen(fpath)+1 ); strncpy(new_path,fpath, strlen(fpath)); if(tf == FTW_D && pfwt->level == 1) { add_dir(new_path); } return 0; }
static void nobackup(void) { add_dir( FOUND, ""); add_file( FOUND, "a", 1); add_dir (NOT_FOUND, "d"); add_file(NOT_FOUND, "d/.nobackup", 0); add_file(NOT_FOUND, "d/b", 1); add_dir (NOT_FOUND, "d/i"); add_file(NOT_FOUND, "d/x", 1); add_file( FOUND, "e", 3); add_dir (NOT_FOUND, "f"); add_file(NOT_FOUND, "f/.exclude", 0); add_file(NOT_FOUND, "f/b", 1); add_dir ( FOUND, "g"); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "nobackup=.nobackup\n" "nobackup=.exclude\n", fullpath); }
static void fifo_individual(void) { add_dir( FOUND, ""); add_fifo( FOUND, "a"); add_fifo( FOUND, "b"); add_fifo_special(FOUND, "c"); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "read_fifo=%s/a\n" "read_fifo=%s/b\n", fullpath, fullpath, fullpath); }
static void symlink_as_blockdev(void) { add_dir( FOUND, ""); add_file( FOUND, "a", 1); add_slnk_raw(FOUND, "e", "a"); add_slnk_raw(FOUND, "f", "a"); snprintf(extra_config, sizeof(extra_config), "include=%s\n" "read_blockdev=%s/e\n" "read_blockdev=%s/f\n", fullpath, fullpath, fullpath); }
void animate_pulse(widget_ptr wid) { int i, dt, d; int x, y; SDL_Rect rect; int speed = 500; if (!pulse_count) { server_pulse(); } rect.w = pipet + 2; rect.h = pipet + 2; i = 0; while (i<pulse_count) { x = pulse_list[i].x; y = pulse_list[i].y; d = pulse_list[i].dir; dt = tick - pulse_list[i].tick; if (dt > speed) { pulse_count--; memmove(&pulse_list[i], &pulse_list[i+1], sizeof(pulse_s) * (pulse_count - i)); add_dir(&x, &y, x, y, d); new_pulse(x, y, (d + 2) % 4); } else { //wrap cases: if (dir[d].x == -1 && 2 * dt > speed && !x) { x += boardw; } if (dir[d].x == 1 && 2 * dt > speed && x == boardw - 1) { x -= boardw; } if (dir[d].y == -1 && 2 * dt > speed && !y) { y += boardh; } if (dir[d].y == 1 && 2 * dt > speed && y == boardh - 1) { y -= boardh; } rect.x = x * (cellw + border) + pipex - 1; rect.x += dir[d].x * (cellw + border) * dt / speed; rect.x += border + padding; rect.y = y * (cellh + border) + border + padding; rect.y += dir[d].y * (cellh + border) * dt / speed; rect.y += pipey - 1; widget_fillrect(wid, &rect, c_pulse); i++; } } }
void populatedb(fsal_posixdb_conn * p_conn, char *path) { int rc; fsal_posixdb_fileinfo_t info; fsal_name_t fsalname; posixfsal_handle_t handle, handle_parent; struct stat buffstat; char *begin, *end, backup; if(path[0] != '/') { fputs("Error : you should provide a complete path", stderr); return; } if(path[strlen(path) - 1] != '/') strcat(path, "/"); /* add the path (given in arguments) to the database */ rc = lstat("/", &buffstat); fsal_internal_posix2posixdb_fileinfo(&buffstat, &info); fsal_internal_posixdb_add_entry(p_conn, NULL, &info, NULL, &handle_parent); begin = end = path; while(*end != '\0') { while(*begin == '/') begin++; if(*begin == '\0') break; end = begin + 1; while(*end != '/' && *end != '\0') end++; backup = *end; *end = '\0'; rc = lstat(path, &buffstat); fsal_internal_posix2posixdb_fileinfo(&buffstat, &info); FSAL_str2name(begin, FSAL_MAX_NAME_LEN, &fsalname); fsal_internal_posixdb_add_entry(p_conn, &fsalname, &info, &handle_parent, &handle); memcpy(&handle_parent, &handle, sizeof(posixfsal_handle_t)); *end = backup; begin = end; } /* add files */ printf("Adding entries in %s... rc=%d ", path, rc); fflush(stdout); add_dir(p_conn, path, &handle_parent); puts("done"); }
static void multi_includes(void) { add_dir( NOT_FOUND, ""); add_file( FOUND, "a", 1); add_file(NOT_FOUND, "b", 2); add_file(NOT_FOUND, "c", 3); add_dir ( FOUND, "d"); add_dir ( FOUND, "d/a"); add_dir (NOT_FOUND, "d/a/b"); add_dir ( FOUND, "d/a/b/c"); add_nostat( FOUND, "d/a/b/c/d"); add_nostat( FOUND, "d/a/b/c/d/e"); add_slnk(NOT_FOUND, "e", "a"); add_hlnk(NOT_FOUND, "g", "a"); snprintf(extra_config, sizeof(extra_config), "include=%s/a\n" "include=%s/d\n" "exclude=%s/d/a/b\n" "include=%s/d/a/b/c\n" "include=%s/d/a/b/c/d\n" "include=%s/d/a/b/c/d/e\n", fullpath, fullpath, fullpath, fullpath, fullpath, fullpath); }
static int check_dir (const char *name) { int ret = -1; struct dirent *ent; char *cur = NULL; DIR *dir = opendir (name); if (dir == NULL) return -1; for (;;) { ent = readdir (dir); if (ent == NULL) break; if (ent->d_type != DT_DIR || strcmp (ent->d_name, ".") == 0 || strcmp (ent->d_name, "..") == 0) continue; if (strcmp (ent->d_name, "cur") == 0 || strcmp (ent->d_name, "new") == 0 || strcmp (ent->d_name, "tmp") == 0) continue; asprintf (&cur, "%s/%s", name, ent->d_name); if (cur == NULL) error (EXIT_FAILURE, errno, "Could not allocate path for %s", ent->d_name); if (access (cur, F_OK) < 0) goto cleanup; if (add_dir (ent->d_name, cur) < 0) error (EXIT_FAILURE, errno, "Could not add directory %s", ent->d_name); free (cur); cur = NULL; } ret = 0; cleanup: free (cur); closedir (dir); return ret; }
void open_dir(struct sfs_fs *sfs, struct cache_inode *current, struct cache_inode *parent) { DIR *dir; if ((dir = opendir(".")) == NULL) { open_bug(sfs, NULL, "opendir failed.\n"); } add_entry(sfs, current, current, "."); add_entry(sfs, current, parent, ".."); struct dirent *direntp; while ((direntp = readdir(dir)) != NULL) { const char *name = direntp->d_name; if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { continue ; } if (name[0] == '.') { continue ; } if (strlen(name) > SFS_MAX_FNAME_LEN) { open_bug(sfs, NULL, "file name is too long: %s\n", name); } struct stat *stat = safe_lstat(name); if (S_ISLNK(stat->st_mode)) { add_link(sfs, current, name, stat->st_ino); } else { int fd; if ((fd = open(name, O_RDONLY)) < 0) { open_bug(sfs, NULL, "open failed: %s\n", name); } if (S_ISDIR(stat->st_mode)) { add_dir(sfs, current, name, dirfd(dir), fd, stat->st_ino); } else if (S_ISREG(stat->st_mode)) { add_file(sfs, current, name, fd, stat->st_ino); } else { char mode = '?'; if (S_ISFIFO(stat->st_mode)) mode = 'f'; if (S_ISSOCK(stat->st_mode)) mode = 's'; if (S_ISCHR(stat->st_mode)) mode = 'c'; if (S_ISBLK(stat->st_mode)) mode = 'b'; show_fullpath(sfs, NULL); warn("unsupported mode %07x (%c): file %s\n", stat->st_mode, mode, name); } close(fd); } } closedir(dir); }
void ffsb_createdir(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *newdir; randdata_t *rd = ft_get_randdata(ft); newdir = add_dir(bf, 0, rd); if (mkdir(newdir->name, S_IRWXU) < 0) { perror("mkdir"); exit(1); } unlock_file_writer(newdir); ft_incr_op(ft, opnum, 1, 0); }
int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int thread_args[NUM_THREADS]; int rc, i; char *search_p; /* read our arguments */ if( argc >= 3 ) { search_s = malloc( strlen( argv[1] )+1 ); search_p = malloc( strlen( argv[2] )+1 ); if( search_s != 0 ) search_s = argv[1]; else { printf("main: Could not allocate memory.\n"); exit(EXIT_FAILURE); } if( search_p != 0 ) search_p = argv[2]; else { printf("main: Could not allocate memory.\n"); exit(EXIT_FAILURE); } } else { printf("Nothing to search for. Exiting...\n"); exit(EXIT_SUCCESS); } printf("Searching for: '%s' in '%s', using %d threads...\n", search_s, search_p, NUM_THREADS); add_dir(search_p); /* create all threads */ for (i=0; i<NUM_THREADS; ++i) { thread_args[i] = i; rc = pthread_create(&threads[i], NULL, do_search, (void *) &thread_args[i]); assert(0 == rc); } /* wait for all threads to complete */ for (i=0; i<NUM_THREADS; ++i) { rc = pthread_join(threads[i], NULL); assert(0 == rc); } exit(EXIT_SUCCESS); }
void add_dir(xirang::zip::reader_writer& zip, xirang::vfs::IVfs& vfs, const xirang::file_path& dir, const xirang::file_path& prefix){ for(auto& i : vfs.children(dir)){ auto filename = dir / i.path; auto st = vfs.state(filename); if (st.state == xirang::fs::st_dir){ add_dir(zip, vfs, filename, prefix); } else if (st.state == xirang::fs::st_regular){ auto fin = vfs.create<xirang::io::read_map>(filename, xirang::io::of_open); zip.append(fin.get<xirang::io::read_map>(), prefix / filename); } else { std::cout << "Unrecongnized file: " << filename.str() << std::endl; } } }
void add_dir(fsal_posixdb_conn * p_conn, char *path, posixfsal_handle_t * p_dir_handle) { DIR *dirp; struct dirent *dp; struct dirent dpe; posixfsal_handle_t new_handle; struct stat buffstat; char path_temp[FSAL_MAX_PATH_LEN]; fsal_status_t st; fsal_posixdb_fileinfo_t info; fsal_name_t fsalname; if((dirp = opendir(path))) { while(!readdir_r(dirp, &dpe, &dp) && dp) { if(!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; if(!strcmp(dp->d_name, ".snapshot")) { fputs("(ignoring .snapshot)", stderr); continue; } strcpy(path_temp, path); strcat(path_temp, dp->d_name); lstat(path_temp, &buffstat); fsal_internal_posix2posixdb_fileinfo(&buffstat, &info); FSAL_str2name(dp->d_name, FSAL_MAX_NAME_LEN, &fsalname); st = fsal_internal_posixdb_add_entry(p_conn, &fsalname, &info, p_dir_handle, &new_handle); if(FSAL_IS_ERROR(st)) { fprintf(stderr, "[Error %i/%i]\n", st.major, st.minor); return; } if(S_ISDIR(buffstat.st_mode)) { strcat(path_temp, "/"); add_dir(p_conn, path_temp, &new_handle); } }; closedir(dirp); } }
/** * Handle a mkdir request * * @param msg client message data * @return Response data, NULL on allocation error */ resp_t *do_mkdir(msg_t *msg) { resp_t *resp = calloc(sizeof(resp_t)); if (!resp) { debug("Failed to allocate response.\n"); return NULL; } if (!add_dir(msg->buf)) { resp->type = MKDIR_OK; cgc_memset(resp->buf, 0, sizeof(resp->buf)); } else { debug("Adding directory failed.\n"); resp->type = MKDIR_FAIL; } return resp; }
static void read_elf_hints(const char *hintsfile, int must_exist) { int fd; struct stat s; void *mapbase; struct elfhints_hdr *hdr; char *strtab; char *dirlist; char *p; if ((fd = open(hintsfile, O_RDONLY)) == -1) { if (errno == ENOENT && !must_exist) return; err(1, "Cannot open \"%s\"", hintsfile); } if (fstat(fd, &s) == -1) err(1, "Cannot stat \"%s\"", hintsfile); if (s.st_size > MAXFILESIZE) errx(1, "\"%s\" is unreasonably large", hintsfile); /* * We use a read-write, private mapping so that we can null-terminate * some strings in it without affecting the underlying file. */ mapbase = mmap(NULL, s.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); if (mapbase == MAP_FAILED) err(1, "Cannot mmap \"%s\"", hintsfile); close(fd); hdr = (struct elfhints_hdr *)mapbase; if (hdr->magic != ELFHINTS_MAGIC) errx(1, "\"%s\": invalid file format", hintsfile); if (hdr->version != 1) errx(1, "\"%s\": unrecognized file version (%d)", hintsfile, hdr->version); strtab = (char *)mapbase + hdr->strtab; dirlist = strtab + hdr->dirlist; if (*dirlist != '\0') while ((p = strsep(&dirlist, ":")) != NULL) add_dir(hintsfile, p, 1); }
void update_elf_hints(const char *hintsfile, int argc, char **argv, int merge) { int i; if (merge) read_elf_hints(hintsfile, 0); for (i = 0; i < argc; i++) { struct stat s; if (stat(argv[i], &s) == -1) warn("warning: %s", argv[i]); else if (S_ISREG(s.st_mode)) read_dirs_from_file(hintsfile, argv[i]); else add_dir(hintsfile, argv[i], 0); } write_elf_hints(hintsfile); }
void getfilelist(const char ***files, int *numfiles, const char *dirname, int sort_by_ext, const char **ignore_patterns, int num_ignore_patterns) { assert(fnams == NULL); assert(nfnams == 0); assert(sfnams == 0); ignores = ignore_patterns; num_ignores = num_ignore_patterns; add_dir(dirname, ""); qsort(fnams, nfnams, sizeof fnams[0], sort_by_ext ? extstrcmp : mystrcmp); *files = (const char **)fnams; *numfiles = nfnams; }
static void read_dirs_from_file(const char *hintsfile, const char *listfile) { FILE *fp; char buf[MAXPATHLEN]; int linenum; if ((fp = fopen(listfile, "r")) == NULL) err(1, "%s", listfile); linenum = 0; while (fgets(buf, sizeof buf, fp) != NULL) { char *cp, *sp; linenum++; cp = buf; /* Skip leading white space. */ while (isspace(*cp)) cp++; if (*cp == '#' || *cp == '\0') continue; sp = cp; /* Advance over the directory name. */ while (!isspace(*cp) && *cp != '\0') cp++; /* Terminate the string and skip trailing white space. */ if (*cp != '\0') { *cp++ = '\0'; while (isspace(*cp)) cp++; } /* Now we had better be at the end of the line. */ if (*cp != '\0') warnx("%s:%d: trailing characters ignored", listfile, linenum); if ((sp = strdup(sp)) == NULL) errx(1, "Out of memory"); add_dir(hintsfile, sp, 0); } fclose(fp); }