void *check_lib(void *arg) { size_t l; char *n; lib_entry *entry; lib_t *lib=(lib_t *)arg; iterator_t *it=chunked_list_iterator(lib->entries); info(ll, "starting checker"); while(iterator_has_next(it)) { lib_entry *e=iterator_next(it); char *f=lib_canonize(lib, e->path); debug(ll, "cheking '%s'", f); if(access(f, R_OK)) iterator_remove(it); free(f); } l=lib->base_path_size+1; n=malloc(l); memcpy(n, lib->base_path, l); entry=malloc(sizeof(lib_entry)); parse_dir(lib, &n, l, entry); free(n); free(entry); }
bool parse_dir(const char *dir_loc, void (*func)(const char *, struct stat&)) { char cwd[16384]; if (getcwd(cwd, sizeof(cwd)) && !chdir(dir_loc)) //chdir() returns 0 on success { DIR *curDir = opendir("."); dirent *curFile; while ((curFile = readdir(curDir))) { char *filename = curFile->d_name; if (!strcmp(filename, ".") || !strcmp(filename, "..")) { continue; } struct stat stat_buffer; if (stat(filename, &stat_buffer)) { continue; } //Directory if (S_ISDIR(stat_buffer.st_mode)) { parse_dir(filename, func); continue; } func(filename, stat_buffer); } closedir(curDir); chdir(cwd); return(true); } return(false); }
/* FUNCION MAIN DEL PROGRAMA BUSCA */ int main(int argc, char *argv[]) { char *list[256]; int num_filts; /*int ejec; int i;*/ accfunc actfunc = NULL; filtfunc filt = NULL; opt_t *opt = (opt_t *) malloc(sizeof(opt_t) + sizeof(char *) * (argc - 6)); if (opt == NULL) exit(ENOMEM); /*Falta memoria*/ if(argc<5 || !strcmp(argv[1],"-h")) { fprintf(POCARG); return 0; } parse_args(argc, argv, opt); actfunc = choose_action((*opt).accion); filt = choose_filter((*opt).filtro); num_filts = parse_dir(opt, filt, list); ejecuta(opt, actfunc, num_filts, list); free(opt); return (RET_VAL); }
int do_MKD(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_dir[MAX_FTP_PATH], fs_dir[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (readonly) return 550; if (!parse_dir(s->dir, arg, ftp_dir)) return 550; if (!ftp_to_fs(ftp_dir, fs_dir)) return 550; if (!CreateDirectory(fs_dir, NULL)) return 550; ftp_printf(s->control, "257 \"%s\" created.\r\n", arg); return 0; }
void init_deepfat(){ df_dev = (dev_t*) kmalloc(sizeof(dev_t)); df_dev->read = NULL; df_dev->write = NULL; df_dev->block_size = CLUSTER_BSIZE; df_root = parse_dir(fat_name_conv("DFATROOT.DIR")); }
static int opendir(ino_t inode, struct iob *io) { struct hs_direct hsdep; uint_t i; int retval; /* Set up the saio request */ io->i_offset = 0; io->i_bn = hdbtodb(inode); io->i_cc = ISO_SECTOR_SIZE; if ((retval = devread(&io->i_si)) != ISO_SECTOR_SIZE) return (0); io->i_offset = 0; io->i_bn = hdbtodb(inode); if (inode != root_ino) return (0); if (parse_dir(io, 0, &hsdep) > 0) { register struct inode *ip = &io->i_ino; bzero(io->i_ino, sizeof (struct inode)); ip->i_size = hsdep.hs_dir.ext_size; ip->i_smode = hsdep.hs_dir.mode; ip->i_number = inode; return (0); } return (1); }
int do_RNTO(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (s->prev_command != cmd_RNFR) return 503; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; if (!(is_file_exists(s->rename) || is_dir_exists(s->rename))) return 550; if (!MoveFile(s->rename, arg)) return 450; return 250; }
int do_RNFR(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; s->curr_command = cmd_NOOP; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (readonly) return 550; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; if (!(is_file_exists(arg) || is_dir_exists(arg))) return 550; s->curr_command = cmd_RNFR; strcpy(s->rename, arg); ftp_printf(s->control, "350 File exists, ready for destination name.\r\n"); return 0; }
void lib_watch_event(struct inotify_event *e, const char *path, void *payload) { lib_entry entry; lib_t *lib=(lib_t*)payload; size_t l=strlen(path)+strlen(e->name)+1; char *f=malloc(l+1); strcpy(f, path); strcat(f, e->name); debug(ll, "watch_even '%s%s'", path, e->name); if(e->mask&IN_CLOSE_WRITE || e->mask&IN_CREATE || e->mask&IN_MOVED_TO) { struct stat buf; stat(f, &buf); if(S_ISDIR(buf.st_mode)) { f[l-1]='/'; f[l]=0; parse_dir(lib, &f, l, &entry); } else parse_file(lib, f, &entry); } else if(e->mask&IN_DELETE || e->mask&IN_DELETE_SELF || e->mask&IN_MOVED_FROM) { iterator_t *it=chunked_list_iterator(lib->entries); while(iterator_has_next(it)) { lib_entry *e=iterator_next(it); if(strncmp(f, e->path, l-1)==0) iterator_remove(it); } } }
/* * get next entry in a directory. */ static struct hs_direct * readdir(struct dirstuff *dirp) { static struct hs_direct hsdep; register struct direct *udp = &hsdep.hs_ufs_dir; struct inode *ip; struct iob *io; daddr_t lbn, d; int off; io = dirp->io; ip = &io->i_ino; for (;;) { if (dirp->loc >= ip->i_size) { return (NULL); } off = dirp->loc & ((1 << ISO_SECTOR_SHIFT) - 1); if (off == 0) { lbn = hdbtodb(dirp->loc >> ISO_SECTOR_SHIFT); io->i_bn = lbn + hdbtodb(ip->i_number); io->i_ma = io->i_buf; io->i_cc = ISO_SECTOR_SIZE; if (devread(&io->i_si) != io->i_cc) { return (NULL); } } dirp->loc += parse_dir(io, off, &hsdep); if (udp->d_reclen == 0 && dirp->loc <= ip->i_size) { dirp->loc = roundup(dirp->loc, ISO_SECTOR_SIZE); continue; } return (&hsdep); }
/** * 根据dirpath指定的路径解析路径目录下的所有文件 * t指定文件类型。 * 返回有向图。 */ digraph* create_digraph(const char* dirpath, src_t t) { base_path = dirpath; switch (t) { case CPP_T: case C_T: parse_fun = parse_c_cpp; break; case JAVA_T: parse_fun = parse_java; break; case CSHARP_T: parse_fun = parse_csharp; break; default: log_err("Unknown src type. %s %d", __FILE__, __LINE__); exit(1); } //初始化目录树 pt = path_tree_init(); path_tree_add(pt, dirpath); int cnt = parse_dir(dirpath); //path_tree_print(pt); buffer_array *all_paths = path_tree_get_all_paths(pt); buffer_array *include_paths; path_tree_node_t *including_ptn; buffer *simple_path; digraph *dg = digraph_init(); size_t i, j; for (i = 0; i < all_paths -> used; ++i) { include_paths = parse_fun(all_paths -> ptr[i] -> ptr); for (j = 0; j < include_paths -> used; ++j) { simple_path = path_tree_simple_path(pt, include_paths -> ptr[j] -> ptr); //log_info("build egde: %s -> %s", all_paths -> ptr[i] -> ptr, include_paths -> ptr[j] -> ptr); if (NULL != simple_path) { digraph_build_edge_string(dg, all_paths -> ptr[i] -> ptr, simple_path -> ptr); } else { digraph_build_edge_string(dg, all_paths -> ptr[i] -> ptr, include_paths -> ptr[j] -> ptr); } buffer_free(simple_path); //digraph_show(dg); } buffer_array_free(include_paths); } buffer_array_free(all_paths); log_info("Return digraph."); return dg; }
static int parse_cmdline_files(parser_fn *parse) { parse_dir(ETC_CMDLINE_D, parse); if (!access(ETC_CMDLINE, R_OK)) parse_file(ETC_CMDLINE, parse); return parse_file(PROC_CMDLINE, parse); };
/** * 解析目录的结构 * 构造目录树 */ static int parse_dir(const char *dirpath) { DIR *dp; struct dirent *dirp; int cnt = 0; if ((dp = opendir(dirpath)) == NULL) { log_err("Open dir error : %s", dirpath); exit(1); } struct stat buf; char fullpath[200]; while((dirp = readdir(dp)) != NULL) { //忽略隐藏目录和文件 if (dirp -> d_name[0] == '.') { continue; } //拼接子文件的完整路径。 strcpy(fullpath, dirpath); //适当的加上/ if (fullpath[strlen(fullpath) - 1] != '/') { strcat(fullpath, "/"); } strcat(fullpath, dirp -> d_name); //获得文件的状态,并判断其是否是目录 if (stat(fullpath, &buf) < 0) { log_err("Get file state error : %s", fullpath); } if (S_ISDIR(buf.st_mode)) //是目录,递归的处理之。 { cnt += parse_dir(fullpath); continue; } if (get_file_type(dirp -> d_name) == UNKNOWN_F_T) { continue; } path_tree_add(pt, fullpath); //log_info("Insert path : %s", fullpath); ++cnt; } closedir(dp); return cnt; }
GNUC_NONNULL_ALL static void add_zip (const char *filename, GNUC_UNUSED void *data) { fs_file_t *f = NULL; bool error = true; uint8_t *dir = NULL; if (unlikely(!fs_open_unsafe(filename, &f, FS_MODE_RDONLY, true))) { return; } size_t size; if (unlikely(!fs_get_size(f, &size) || size <= ZIP_ENTRY_SIZE + sizeof(zip_end_header_t))) { fs_print_error(f, "bad size"); goto done; } zip_end_header_t end; if (unlikely(!get_end_header(f, size, &end))) { fs_print_error(f, "can\'t find end of central dir"); goto done; } if (unlikely(end.disk || end.disk_wcd)) { fs_print_error(f, "multivolume zip; not supported"); goto done; } zip_t *z; if (unlikely(!(dir = mem_alloc(fs_mem_pool, end.size)) || !fs_seek(f, end.offset, FS_ORIGIN_START) || !fs_read(f, dir, end.size, NULL, "central dir read failed") || !parse_dir(f, dir, &end, &z))) { fs_print_error(f, "failed to parse central directory"); goto done; } z->f = f; z->next = zips; zips = z; qsort(z->files, z->num_files, sizeof(z->files[0]), cmp_file_zip); g_message("added \"%s\" with %i files", filename, z->num_files); error = false; done: if (error) { fs_close(f); } mem_free(dir); }
/* * Handles a special file. */ void parse_special(unsigned char *in, struct detox_options *options) { struct stat stat_info; char *new_file, *work; int err; /* detox, then parse_dir if a symlink to a dir */ new_file = parse_file(in, options); if (!new_file) { return; } err = lstat(new_file, &stat_info); if (err == -1) { fprintf(stderr, "Unable to stat %s\n", in); free(new_file); return; } if (options->recurse && S_ISLNK(stat_info.st_mode)) { work = malloc(1024); if (!work) { fprintf(stderr, "out of memory: %s\n", strerror(errno)); free(new_file); return; } memset(work, 0, 1024); err = readlink(new_file, work, 1023); if (err == -1) { fprintf(stderr, "Unable to read symbolic link %s\n", in); free(work); free(new_file); } err = lstat(work, &stat_info); if (err == -1) { fprintf(stderr, "Unable to follow symbolic link %s\n", in); free(work); free(new_file); return; } if (S_ISDIR(stat_info.st_mode)) { parse_dir(work, options); } free(work); } free(new_file); }
int do_CDUP(ftp_session *s, char *param) { char new_dir[MAX_FTP_PATH]; MATCH_CRLF(param); if (!parse_dir(s->dir, "..", new_dir)) return 550; if (!is_ftp_dir_exists(new_dir)) return 550; strcpy(s->dir, new_dir); return 200; }
bool parse_path(const char *path, void (*func)(const char *, struct stat&)) { struct stat stat_buffer; if (!stat(path, &stat_buffer)) { if (S_ISDIR(stat_buffer.st_mode)) { return(parse_dir(path, func)); } func(path, stat_buffer); return(true); } return(false); }
void SLNFilterParseOptions(strarg_t const qs, SLNFilterPosition *const start, uint64_t *const count, int *const dir, bool *const wait) { static strarg_t const fields[] = { "start", "count", "dir", "wait", }; str_t *values[numberof(fields)] = {}; QSValuesParse(qs, values, fields, numberof(fields)); if(start) parse_start(values[0], start); if(count) *count = parse_count(values[1], *count); if(dir) *dir = parse_dir(values[2], *dir); if(wait) *wait = parse_wait(values[3]); QSValuesCleanup(values, numberof(values)); }
int init_scan_top_level (void) { DIR *dir_ptr; struct dirent *entry_pointer; int len; if (getrepo()) { parse_dir(g_repo, 0, strlen(g_repo)); } else { perror ("could not determine DCS env var setting"); } return 0; }
void parse_dir(lib_t *lib, char **name, size_t l, lib_entry *entry) { int s=strlen(*name); struct dirent *d; DIR *dir=opendir(*name); if(!dir) { error(ll, "failed to read dir '%s'", *name); return; } watch(lib->watch, *name); while((d=readdir(dir))!=NULL) { if(d->d_name[0]=='.') // skip hidden file continue; int s2=strlen(d->d_name); if(d->d_type==DT_DIR) { if(l<s+s2+1) { l=s+s2+1; *name=realloc(*name, l+1); } memcpy(*name+s, d->d_name, s2+1); (*name)[s+s2]='/'; (*name)[s+s2+1]=0; debug(ll, "parse_dir(%s)", *name); parse_dir(lib, name, l, entry); debug(ll, "return %s", *name); } else { filecount++; if(l<s+s2) { l=s+s2; *name=realloc(*name, l+1); } memcpy(*name+s, d->d_name, s2+1); (*name)[s+s2]=0; // read file metadata if(!find(lib, *name+lib->base_path_size)) parse_file(lib, *name, entry); } } info(ll, "parsed %d files, %d keept", filecount, lib->entries->size); closedir(dir); }
void init_initrd(void) { if (multiboot_info.mods_count < 1) { panic("No initrd."); } void *disk; char *params; int size = mod_load(0, &disk, ¶ms); dbg_printf(DBG_FS, "Loading initrd '%s' at %p with %d bytes length.\n", params, disk, size); if (!check_img(disk)) { panic("Module 1 is not a kOS initrd (%s)\n", params); } root = parse_dir(disk + sizeof(struct id_header), disk); vfs_register(&initrd); }
void main (int argc, char ** argv) { while (1) { int err; if (argc != 2) { puts ("usage: mkromfs <dir>"); err = 1; break; } printf ("Starting from %s directory.\n", argv [1]); puts ("\nParsing file system..."); list_init (&_inodes); inode_build_t * root_node = inode_alloc (NULL, argv [1]); if (!root_node) break; root_node->flags = INODE_DIR; err = parse_dir (NULL, root_node, argv [1]); if (err) break; puts ("End of parsing."); printf ("\nTotal inodes: %u\n", _inodes.count); puts ("\nCompiling file system..."); err = compile_fs (); if (err) break; puts ("End of compilation."); break; } }
int do_CWD(ftp_session *s, char *param) { int len; char dir[MAX_FTP_PATH], new_dir[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, dir, sizeof(dir)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (!parse_dir(s->dir, dir, new_dir)) return 550; if (!is_ftp_dir_exists(new_dir)) return 550; strcpy(s->dir, new_dir); return 250; }
static struct inode *parse_dir(struct id_entry *dir, void *disk) { if (dir->type != ID_TYPE_DIR) { panic("Tried to parse %s as a dir, but it's a file.\n", (char*)id_get(dir, name, disk)); } dbg_vprintf(DBG_FS, "creating dir %s\n", (char*)id_get(dir, name, disk)); struct inode *ino = new_inode(dir, disk); ino->flags = FS_DIR; list_t *entries = list_create(); ino->impl = (dword)entries; if (id_get(dir, count, disk) > 0) { struct id_entry *entry = id_get(dir, content, disk); while (entry) { struct inode *e = NULL; if (entry->type == ID_TYPE_FILE) { e = parse_file(entry, disk); } else if (entry->type == ID_TYPE_DIR) { e = parse_dir(entry, disk); } else { panic("Invalid type: %d\n", entry->type); } list_add_back(entries, e); entry = id_get(entry, next, disk); } } dbg_vprintf(DBG_FS, "dir done!\n"); return ino; }
static void get_procs(void) { struct proc *p; int i; p = prev_proc; prev_proc = proc; proc = p; if (proc == NULL) { proc = malloc(nr_total * sizeof(proc[0])); if (proc == NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } } for (i = 0; i < nr_total; i++) proc[i].p_flags = 0; parse_dir(); }
int do_DELE_RMD(ftp_session *s, char *param) { int len, attr, del_mode; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (readonly) return 550; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; del_mode = s->curr_command == cmd_DELE; if (del_mode && !is_file_exists(arg)) return 550; if (!del_mode && !is_dir_exists(arg)) return 550; attr = GetFileAttributes(arg); SetFileAttributes(arg, 0); if (del_mode ? !DeleteFile(arg) : !RemoveDirectory(arg)) { SetFileAttributes(arg, attr); return 450; } return 250; }
int xbps_init(struct xbps_handle *xhp) { struct utsname un; char cwd[PATH_MAX-1], *buf; const char *repodir, *native_arch; int rv; assert(xhp != NULL); /* get cwd */ if (getcwd(cwd, sizeof(cwd)) == NULL) return ENOTSUP; /* set conffile */ if (xhp->conffile[0] == '\0') { snprintf(xhp->conffile, sizeof(xhp->conffile), XBPS_CONF_DEF); } else { buf = strdup(xhp->conffile); snprintf(xhp->conffile, sizeof(xhp->conffile), "%s/%s", cwd, buf); free(buf); } /* Set rootdir */ if (xhp->rootdir[0] == '\0') { xhp->rootdir[0] = '/'; xhp->rootdir[1] = '\0'; } else if (xhp->rootdir[0] != '/') { buf = strdup(xhp->rootdir); snprintf(xhp->rootdir, sizeof(xhp->rootdir), "%s/%s", cwd, buf); free(buf); } /* parse configuration file */ xbps_dbg_printf(xhp, "%s\n", XBPS_RELVER); if ((rv = parse_file(xhp, cwd, xhp->conffile, false, false)) != 0) { xbps_dbg_printf(xhp, "Using built-in defaults\n"); } /* Set cachedir */ if (xhp->cachedir[0] == '\0') { snprintf(xhp->cachedir, sizeof(xhp->cachedir), "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_CACHE_PATH); } else if (xhp->cachedir[0] != '/') { /* relative path */ buf = strdup(xhp->cachedir); snprintf(xhp->cachedir, sizeof(xhp->cachedir), "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); free(buf); } /* Set metadir */ if (xhp->metadir[0] == '\0') { snprintf(xhp->metadir, sizeof(xhp->metadir), "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_META_PATH); } else if (xhp->metadir[0] != '/') { /* relative path */ buf = strdup(xhp->metadir); snprintf(xhp->metadir, sizeof(xhp->metadir), "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); free(buf); } /* process virtualpkg.d dirs */ if ((rv = parse_dir(xhp, cwd, XBPS_SYS_VPKG_PATH, XBPS_VPKG_PATH, true)) != 0) return rv; /* process repo.d dirs */ if ((rv = parse_dir(xhp, cwd, XBPS_SYS_REPOD_PATH, XBPS_REPOD_PATH, false)) != 0) return rv; /* process preserve.d dirs */ if ((rv = parse_dir(xhp, cwd, XBPS_SYS_PRESERVED_PATH, XBPS_PRESERVED_PATH, false)) != 0) return rv; xhp->target_arch = getenv("XBPS_TARGET_ARCH"); if ((native_arch = getenv("XBPS_ARCH")) != NULL) { strlcpy(xhp->native_arch, native_arch, sizeof(xhp->native_arch)); } else { uname(&un); strlcpy(xhp->native_arch, un.machine, sizeof(xhp->native_arch)); } assert(xhp->native_arch); xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST); xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir); xbps_dbg_printf(xhp, "metadir=%s\n", xhp->metadir); xbps_dbg_printf(xhp, "cachedir=%s\n", xhp->cachedir); xbps_dbg_printf(xhp, "syslog=%s\n", xhp->flags & XBPS_FLAG_DISABLE_SYSLOG ? "false" : "true"); xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch); xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch); if (xhp->flags & XBPS_FLAG_DEBUG) { for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { xbps_array_get_cstring_nocopy(xhp->repositories, i, &repodir); xbps_dbg_printf(xhp, "Repository[%u]=%s\n", i, repodir); } } /* Going back to old working directory */ if (chdir(cwd) == -1) xbps_dbg_printf(xhp, "%s: cannot chdir to %s: %s\n", __func__, cwd, strerror(errno)); return 0; }
void playcd(int count) { if (count == 1) { //play disc std::list<MyPair> filetypes = movie_conf->p_filetypes_m(); std::string file_types; foreach (MyPair& filetype, filetypes) file_types += filetype.first + "|"; file_types = file_types.substr(0, file_types.size()-1); //-type f -printf \"'%p' std::string play_cmd = "find '" + cd->get_mount_point() + "' -regextype posix-egrep -follow -maxdepth 8 -iregex '.*\\.(" + file_types + ")' | xargs "; Plugins *plugins = S_Plugins::get_instance(); MoviePlayerPlugin *plugin = plugins->find(plugins->movie_players, opts.movie_player()); if (plugin == 0) { std::cerr << "something really wrong, movie player not found!" << std::endl; return; } if (plugin->player->wants_exclusivity()) render->device->unlock(); plugin->player->play_disc(play_cmd); if (plugin->player->wants_exclusivity()) render->device->lock(); } else { navigating_media = true; top_media_folders.clear(); top_media_folders.push_back(cd->get_mount_point()); std::vector<T> backup_files; backup_files = files; std::stack<std::pair<std::list<std::string>, int > > backup_folders = folders; std::list<std::string> dirs; dirs.push_back(cd->get_mount_point()); files = parse_dir(dirs); while (!folders.empty()) folders.pop(); folders.push(std::make_pair(dirs, 0)); S_BackgroundUpdater::get_instance()->run_once(boost::bind(&MovieTemplate::check_for_changes, this)); mainloop(); files = backup_files; folders = backup_folders; navigating_media = false; } //umount the disc run::external_program("umount '" + cd->get_mount_point() + "'"); }
/* parses the FreeBSD ports INDEX file and creates a list of categories with dedicated ports, it also creates a meta-category "all", all lists and categories are sorted ascending. */ int parse_index() { FILE *fd; int c, i, readyToken; int pipes = 0; char tok[MAX_TOKEN]; extern Config config; extern List *lprts; extern List *lcats; extern void *exists; extern TNode *tcat; TNode *tdirs; TNode *tprt = NULL; List *lpdir = (List *)malloc(sizeof(List)); Port *p, *dprt; int num_of_inst_ports = 0; /* init */ p = NULL; tcat = NULL; lpdir->num_of_items = 0; lpdir->head = NULL; lpdir->tail = NULL; if ((fd = fopen(config.index_file, "r")) == NULL) return ERROR_OPEN_INDEX; /* error */ /* parse installed pkgs */ tdirs = parse_dir(config.inst_pkg_dir); /* parse ports dir and create list */ create_inorder_list(lpdir, parse_dir(config.ports_dir)); i = 0; readyToken = 0; /* token not ready */ while (feof(fd) == 0) { c = fgetc(fd); /* get next char */ switch (c) { case '|': /* next token */ readyToken = 1; /* ready token */ break; case '\n': /* end of port */ #if defined(__FreeBSD__) if (pipes != PORT_URL) /* seems to be some strange INDEX */ return ERROR_CORRUPT_INDEX; #endif readyToken = 1; /* tail token of port ready */ break; default: if ((pipes != PORT_CATEGORY) && (pipes != PORT_BUILD_DEPENDENCY) && (pipes != PORT_RUN_DEPENDENCY)) /* default, no port category, build dep or run dep modus */ tok[i++] = (char)c; break; } /* to speed up the parsing, we also parse categories here, I guessed if it'll be senseful to also parse BDEP and RDEP, but this makes no sense until there aren't all entries scanned */ if (pipes == PORT_CATEGORY) { /* port category mode */ if ((c == ' ') || (c == '|')) { if (i > 0) { /* maybe there're ports without a category */ tok[i] = '\0'; /* terminate current cat token */ add_list_item(p->lcats, add_category(tok, lpdir)); i = 0; /* reset i */ } } else { /* inside a token */ tok[i++] = (char)c; } } else if ((pipes == PORT_BUILD_DEPENDENCY) || (pipes == PORT_RUN_DEPENDENCY)) { /* port build/run dep mode */ if ((c == ' ') || (c == '|')) { if (i > 0) { /* maybe there're ports without a build dep */ tok[i] = '\0'; dprt = create_port(tok, tdirs); exists = NULL; tprt = add_tree_item(tprt, dprt, cmp_name); if (exists != NULL) { free_port(dprt); dprt = (Port *)((TNode *)exists)->item; } else { if (dprt->state >= STATE_INSTALLED) num_of_inst_ports++; } if (pipes == PORT_BUILD_DEPENDENCY) { add_list_item(p->lbdep, dprt); } else if (pipes == PORT_RUN_DEPENDENCY) { add_list_item(p->lrdep, dprt); } /* add also p to dprt->ldep, so that dprt knows the port for which dprt is a dependency, this helps seeking for unused ports */ add_list_item(dprt->ldep, p); i = 0; /* reset i */ } } else { /* inside a token */ tok[i++] = (char)c; } } if (readyToken == 1) { /* a new token is ready */ tok[i] = '\0'; /* terminate current token */ switch (pipes) { case PORT_NAME_VERSION: p = create_port(tok, tdirs); /* add the port */ exists = NULL; tprt = add_tree_item(tprt, p, cmp_name); if (exists != NULL) { free_port(p); p = (Port *)((TNode *)exists)->item; } else { if (p->state >= STATE_INSTALLED) num_of_inst_ports++; } break; case PORT_PATH: p->path = strdup(tok); break; #if defined(__FreeBSD__) case PORT_INSTALL_PREFIX: p->instpfx = strdup(tok); break; #endif case PORT_DESCR: p->descr = strdup(tok); break; case PORT_PKGDESCR: p->pathpkgdesc = strdup(tok); break; case PORT_MAINTAINER: p->maintainer = strdup(tok); break; #if defined(__FreeBSD__) case PORT_URL: p->url = strdup(tok); pipes = -1; break; #endif } readyToken = i = 0; /* token processed, not ready token anymore */ pipes++; } } fclose(fd); /* close INDEX file */ create_inorder_list(lcats, tcat); create_inorder_list(lprts, tprt); create_categories(num_of_inst_ports); free_tree(tdirs); /* finished */ return (0); }
fs_node_t* parse_dir(char* dir){ fs_node_t* node = mk_empty_dnode(); fs_node_t* parent = node; char* fat_buff = (char*) fat_load_full(dir); char* str = prep_str(fat_buff); ASSERT(strcmp(str, "DEEPFAT") == 0); str = next_str(str); ASSERT(strcmp(str, "DEEPDIR") == 0); str = next_str(str); while(strcmp(str, "ENDDIR") != 0){ char* ent = str; str = next_str(ent); fs_node_t* sub; /* vga_puts("\t* creating '"); vga_puts(str); vga_puts("'\n"); */ if(strcmp(ent, "DIR") == 0){ char* name = str; str = next_str(str); sub = parse_dir(fat_name_conv(str)); strmov(sub->name, name); strmov(sub->dos_name, str); fat_dir_t* file = fat_dir_search(fat_name_conv(str)); sub->inode = file->cluster_low; sub->length = file->bytes; sub->flags = FS_DIRECTORY; //Callbacks for basic VFS manipulation sub->open = df_open; sub->close = df_close; sub->readdir = readdir_generic; sub->finddir = df_finddir; } else if(strcmp(ent, "FIL") == 0){ char* name = str; str = next_str(str); sub = mk_empty_fnode(); strmov(sub->dos_name, str); fat_dir_t* file = fat_dir_search(fat_name_conv(str)); strmov(sub->name, name); sub->inode = file->cluster_low; sub->length = file->bytes; } else{ PANIC("bad deepFAT directory entry"); } str = ent; str = next_str(str); str = next_str(str); str = next_str(str); if(parent->holds == NULL){ parent->holds = sub; node = sub; } else{ node->link = sub; node = sub; } } kfree(fat_buff); return parent; }