Example #1
0
static int replay_attrib(direntry_t *entry, MainParam_t *mp)
{
	if ( (IS_ARCHIVE(entry) && IS_DIR(entry)) ||
		 (!IS_ARCHIVE(entry) && !IS_DIR(entry)) ||
		 IS_SYSTEM(entry) || IS_HIDDEN(entry)) {

		printf("mattrib ");

		if (IS_ARCHIVE(entry) && IS_DIR(entry)) {
			printf("+a ");
		}

		if (!IS_ARCHIVE(entry) && !IS_DIR(entry)) {
			printf("-a ");
		}

		if (IS_SYSTEM(entry)) {
			printf("+s ");
		}

		if (IS_HIDDEN(entry)) {
			printf("+h ");
		}

		fprintPwd(stdout, entry, 1);
		printf("\n");
	}
	return GOT_ONE;
}
Example #2
0
static void* fhs_event_process(void *data)
{
        struct fe_handler *feh = (struct fe_handler*)data;
        FAMEvent fe;
        FAMRequest fr;
        FAMConnection fc;
        char*  root_path;

        root_path = g_hash_table_lookup(feh->ohh->config, "root_path");

        FAMOpen(&fc);
        FAMMonitorDirectory(&fc, root_path, &fr, REQ_RES);

        while(!feh->closing) { 
/*
        The old code is:
               FAMNextEvent(&fc, &fe);
        The new code is
                if (1 == FAMPending(&fc)) {
                        FAMNextEvent(&fc, &fe);
                }else  continue;

        In the old code, if this thread is processing FAMNextEvent and 
        then feh->closing is set by another thread, this thread is still
        hung up. so the synchronized call is changed as asychronized call
        (polling call) though I don't like this mode.
 
*/  
                if (1 == FAMPending(&fc)) {
                        FAMNextEvent(&fc, &fe);
                }else  continue; 

                if ((fe.userdata == REQ_RES) &&
                    ((fe.code == FAMCreated) || (fe.code == FAMExists))) {
                        if (!IS_DIR(fe.filename))
                                fhs_event_add_resource(feh, fe.filename, &fe);
                }else if ((fe.userdata == REQ_RDR) && (fe.code == FAMDeleted)) {
                     	if (!IS_DIR(fe.filename))
                             	fhs_event_remove_resource(feh, &fe);
                      	else
                  		printf("faint! why delete root path\n");
                }else if (fe.userdata == REQ_RDR) {
                        if (((fe.code == FAMChanged) || (fe.code == FAMExists))&&
                            ((!strcmp(fe.filename, "reading"))||
                             (!strcmp(fe.filename, "thres")))) {
                                fhs_event_sensor_update(feh, &fe);
                        }
                }
        } 
        FAMClose(&fc);

        return 0;
}
Example #3
0
int direct_traverse(const char *direct, int recurs, int (*visit)(char *file, void *handle_ptr, void *bak_path), 
			void *handle_ptr, void *bak_path)
{
	if (direct == NULL || strlen(direct) < 1)
	{
		return -1;
	}
	int len;
	char temp[256];
	
	/* È¥µôĩβµÄ'/' */
	len = strlen(direct);
	strcpy(temp, direct);
	if (temp[len - 1] == '/' && len != 1)
		temp[len - 1] = '\0';
	
	if (IS_DIR(temp))
	{
		direct_traverse_core(temp, recurs, visit, handle_ptr, bak_path);
	}
	else
	{
		visit(temp, handle_ptr, bak_path);
	}
	
	return 0;
}
Example #4
0
static int fs_readwrite(struct file_s *flip, char *buf, unsigned int n, int flag)
{
    struct inode_s *ino = flip->f_ino;
    unsigned int pos = flip->f_pos;

    if (ino == NULL)
        return ERROR;
 
    /* if its a directory, error */
    if (IS_DIR(ino->i_mode))
        return ERROR;
       
    /* check limit of file in read operation */
    if (flag == FS_READ)
        n = MIN(n, ino->i_size - pos);

    /* read/write the buffer */
    if ( (pos = copy_file(buf, n, pos, ino, flag)) == ERROR)
        return ERROR;

    /* check how much did we read/write */
    n = pos - flip->f_pos;
    
    /* update inode size */
    if (pos > ino->i_size && flag == FS_WRITE) {
        ino->i_size = pos;
        ino->i_dirty = 1;
    }

    /* set new filepos */
    flip->f_pos = pos;

    return n;
}
Example #5
0
/*
 * Lookup vnode for the specified file/directory.
 * The vnode data will be set properly.
 */
static int
fatfs_lookup(vnode_t dvp, char *name, vnode_t vp)
{
    struct fatfsmount *fmp;
    struct fat_dirent *de;
    struct fatfs_node *np;
    int error;

    if (*name == '\0')
        return ENOENT;

    fmp = vp->v_mount->m_data;
    mutex_lock(&fmp->lock);

    DPRINTF(("fatfs_lookup: name=%s\n", name));

    np = vp->v_data;
    error = fatfs_lookup_node(dvp, name, np);
    if (error) {
        DPRINTF(("fatfs_lookup: failed!! name=%s\n", name));
        mutex_unlock(&fmp->lock);
        return error;
    }
    de = &np->dirent;
    vp->v_type = IS_DIR(de) ? VDIR : VREG;
    fat_attr_to_mode(de->attr, &vp->v_mode);
    vp->v_mode = ALLPERMS;
    vp->v_size = de->size;
    vp->v_blkno = (de->cluster_hi << 16) | de->cluster;

    DPRINTF(("fatfs_lookup: cl=%d\n", vp->v_blkno));
    mutex_unlock(&fmp->lock);
    return 0;
}
Example #6
0
void deleteNode(VolInfo* volInfo, BkDir* parentDir, char* nodeToDeleteName)
{
    BkFileBase** childPtr;
    BkFileBase* nodeToFree;
    
    childPtr = &(parentDir->children);
    while(*childPtr != NULL)
    {
        if( strcmp((*childPtr)->name, nodeToDeleteName) == 0 )
        {
            nodeToFree = *childPtr;
            
            *childPtr = (*childPtr)->next;
            
            if( IS_DIR(nodeToFree->posixFileMode) )
            {
                deleteDirContents(volInfo, BK_DIR_PTR(nodeToFree));
            }
            else if ( IS_REG_FILE(nodeToFree->posixFileMode) )
            {
                deleteRegFileContents(volInfo, BK_FILE_PTR(nodeToFree));
            }
            /* else the free below will be enough */
            
            free(nodeToFree);
            
            break;
        }
        
        childPtr = &((*childPtr)->next);
    }
}
Example #7
0
/**
 * @brief	list the directory contents stored in the array
 * @param	fpsockout	socket file stream
 * 		dirarray	directory contents and the file info store
 *
 */
void writebody(FILE *fpsockout, struct statdir **dirarray)
{
        int i = 0;
        char mtime[MAXDATELEN];
        char size[MAXSIZELEN] = "";
        char *name;
	
	/* read from the array and if a file use FILFORMAT to write to the 
	 * socket else if a directory use DIRFORMAT
	 */
        while ( dirarray[i] != NULL ) {
                name    = dirarray[i]->dir_ent->d_name;
                fSize(size, dirarray[i]->statbuf->st_size);
                modtime(mtime, dirarray[i]->statbuf->st_mtime);

                if ( IS_REG(dirarray[i]->statbuf ) )
                        fprintf(fpsockout, FILFORMAT, name, name, mtime, size);

                else if ( IS_DIR(dirarray[i]->statbuf ) )
                        fprintf(fpsockout, DIRFORMAT, name, name, mtime);

                i++;
        }
        fflush(fpsockout);
}
Example #8
0
int print_removable(struct hash *hash, char *remove)
{
    struct node *n;
    struct tree *t;
    struct tree_node *e;
    char **dirs, **files;
    int cnt, dir_cnt, file_cnt, i;

    if ((n = hash_search(hash, remove)) == NULL) {
        fprintf(stderr,
                "bee-dep: print_removable: cannot find \"%s\"\n",
                remove);
        return 1;
    }

    if (!IS_PKG(n)) {
        fprintf(stderr,
                "bee-dep: print_removable: \"%s\": no such package\n",
                remove);
        return 1;
    }

    t = tree_new();

    search_removable(hash, n, t, remove);

    cnt = tree_count(t);

    if ((dirs = calloc(cnt, sizeof(*dirs))) == NULL
        || (files = calloc(cnt, sizeof(*files))) == NULL) {
        perror("bee-dep: print_removable: calloc");
        return 1;
    }

    e = tree_first(t->root);
    dir_cnt = file_cnt = 0;

    while (e) {
        if (IS_DIR(e->n))
            dirs[dir_cnt++]   = e->n->name;
        else
            files[file_cnt++] = e->n->name;

        e = tree_next(e);
    }

    sort_dirs(dirs, dir_cnt);

    for (i = 0; i < file_cnt; i++)
        puts(files[i]);

    for (i = 0; i < dir_cnt; i++)
        puts(dirs[i]);

    free(dirs);
    free(files);
    tree_free(t);

    return 0;
}
Example #9
0
void scan_plugin_dir(char const* path, char const* app_name, JSObjectRef array)
{
    if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
        return;
    }

    JSContextRef ctx = get_global_context();
    GDir* dir = g_dir_open(path, 0, NULL);
    if (dir != NULL) {
        const char* file_name = NULL;
        for (int i=0; NULL != (file_name = g_dir_read_name(dir)); ) {
            char* full_path = g_build_filename(path, file_name, NULL);

            if (IS_DIR(full_path) && is_plugin(full_path)) {
                char* js_name = g_strconcat(file_name, ".js", NULL);
                char* js_path = g_build_filename(full_path, js_name, NULL);
                g_free(js_name);

                char* key = g_strconcat(app_name, ":", file_name, NULL);
                if (g_hash_table_contains(enabled_plugins, key)) {

                    JSValueRef v = jsvalue_from_cstr(ctx, js_path);
                    json_array_insert(array, i++, v);
                }

                g_free(key);
                g_free(js_path);
            }

            g_free(full_path);
        }

        g_dir_close(dir);
    }
}
Example #10
0
int write_fs(vnode *node, off_t offset, size_t size, const char *buffer)
{
	if (IS_DIR(node)) return -EISDIR;
	if (node->i_op && node->i_op->f_op && node->i_op->f_op->write)
		return node->i_op->f_op->write(node, offset, size, buffer);
	else return -EINVAL;
}
Example #11
0
//遍历文件夹de递归函数
void List_Files_Core(const char *path, int recursive)
{
         DIR *pdir;
         struct dirent *pdirent;
         char temp[256];
         pdir = opendir(path);
         if(pdir)
         {
                 while(pdirent = readdir(pdir))
                 {
                           //跳过"."和".."
                           if(strcmp(pdirent->d_name, ".") == 0
                                     || strcmp(pdirent->d_name, "..") == 0)
                                   continue;
                           sprintf(temp, "%s/%s", path, pdirent->d_name);
                           printf("%s\n", temp);
                           //当temp为目录并且recursive为1的时候递归处理子目录
                           if(IS_DIR(temp) && recursive)
                           {
                                   List_Files_Core(temp, recursive);
                           }
                 }
          }
         else
         {
                  printf("opendir error:%s\n", path);
          }
          closedir(pdir);
}
Example #12
0
void sortDir(DirToWrite* dir, int filenameType)
{
    BaseToWrite* child;
    BaseToWrite** outerPtr;
    BaseToWrite** innerPtr;
    
    child = dir->children;
    while(child != NULL)
    {
        if(IS_DIR(child->posixFileMode))
            sortDir(DIRTW_PTR(child), filenameType);
        
        child = child->next;
    }
    
    outerPtr = &(dir->children);
    while(*outerPtr != NULL)
    {
        innerPtr = &((*outerPtr)->next);
        while(*innerPtr != NULL)
        {
            if( (filenameType & FNTYPE_JOLIET &&
                 rightIsBigger((*innerPtr)->nameJoliet, (*outerPtr)->nameJoliet)) || 
                (filenameType & FNTYPE_9660 &&
                 rightIsBigger((*innerPtr)->name9660, (*outerPtr)->name9660)) )
            {
                BaseToWrite* outer = *outerPtr;
                BaseToWrite* inner = *innerPtr;
                
                if( (*outerPtr)->next != *innerPtr )
                {
                    BaseToWrite* oldInnerNext = inner->next;

                    *outerPtr = inner;
                    *innerPtr = outer;
                    
                    inner->next = outer->next;
                    outer->next = oldInnerNext;
                }
                else
                {
                    BaseToWrite* oldInnerNext = inner->next;

                    *outerPtr = inner;
                    innerPtr = &(inner->next);
                    
                    inner->next = outer;
                    outer->next = oldInnerNext;
                }
            }
            
            innerPtr = &((*innerPtr)->next);
        }
        
        outerPtr = &((*outerPtr)->next);
    }
}
Example #13
0
File: read.c Project: Sciumo/minix
/*===========================================================================*
 *				do_read					     *
 *===========================================================================*/
int do_read()
{
/* Read data from a file.
 */
  struct inode *ino;
  u64_t pos;
  size_t count, size;
  vir_bytes off;
  char *ptr;
  int r, chunk;

  if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
	return EINVAL;

  if (IS_DIR(ino)) return EISDIR;

  if ((r = get_handle(ino)) != OK)
	return r;

  pos = make64(m_in.REQ_SEEK_POS_LO, m_in.REQ_SEEK_POS_HI);
  count = m_in.REQ_NBYTES;

  assert(count > 0);

  /* Use the buffer from below to eliminate extra copying. */
  size = sffs_table->t_readbuf(&ptr);
  off = 0;

  while (count > 0) {
	chunk = MIN(count, size);

	if ((r = sffs_table->t_read(ino->i_file, ptr, chunk, pos)) <= 0)
		break;

	chunk = r;

	r = sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, off,
		(vir_bytes) ptr, chunk, D);

	if (r != OK)
		break;

	count -= chunk;
	off += chunk;
	pos = add64u(pos, chunk);
  }

  if (r < 0)
	return r;

  m_out.RES_SEEK_POS_HI = ex64hi(pos);
  m_out.RES_SEEK_POS_LO = ex64lo(pos);
  m_out.RES_NBYTES = off;

  return OK;
}
Example #14
0
static void
temp(gpointer key, gpointer value, gpointer data)
{
	GPtrArray *array = (GPtrArray *) data;
	g_ptr_array_add(array, value);

	DirItem* item = (DirItem*)value;
	if (IS_DIR(item)) printf("***  %s\n", item->leafname);
	printf("  %s basetype=%i\n", item->leafname, item->base_type);
}
Example #15
0
static void* fhs_event_process(void *data)
{
        struct fe_handler *feh = (struct fe_handler*)data;
        FAMEvent fe;
        FAMRequest fr;
        FAMConnection fc;
        char*  root_path;

#ifndef UNIT_TEST 
        root_path = g_hash_table_lookup(feh->ohh->config, "root_path");
#else
        root_path = "/home/guorj/HPI/openhpi/src/plugins/simulator/test/resources";
#endif

        FAMOpen(&fc);
        FAMMonitorDirectory(&fc, root_path, &fr, (void*)req_res);

        while(!feh->done) {   

                FAMNextEvent(&fc, &fe);
                if ((fe.userdata == (void *)req_res) &&
                    ((fe.code == FAMCreated) || (fe.code == FAMExists))) {
                        if (!IS_DIR(fe.filename))
                                fhs_event_add_resource(feh, fe.filename, &fe);
                }else if ((fe.userdata == (void*) req_res) && (fe.code == FAMDeleted)) {
                     	if (!IS_DIR(fe.filename))
                             	fhs_event_remove_resource(feh, &fe);
                      	else
                  		printf("faint! why delete root path\n");
                }else if (fe.userdata == (void *)req_rdr) {
                        if (((fe.code == FAMChanged) || (fe.code == FAMExists))&&
                            ((!strcmp(fe.filename, "reading"))||
                             (!strcmp(fe.filename, "thres")))) {
                                fhs_event_sensor_update(feh, &fe);
                        }
                }
        } 
        FAMClose(&fc);
#if 0
        free all resource id and rdr id;
#endif
        return 0;
}
static int _dos_loop(Stream_t *Dir, MainParam_t *mp, const char *filename)
{	
	Stream_t *MyFile=0;
	direntry_t entry;
	int ret;
	int r;
	
	ret = 0;
	r=0;
	initializeDirentry(&entry, Dir);
	while(!got_signal &&
	      (r=vfat_lookup(&entry, filename, -1,
			     mp->lookupflags, mp->shortname, 
			     mp->longname)) == 0 ){
		mp->File = NULL;
		if(!checkForDot(mp->lookupflags,entry.name)) {
			MyFile = 0;
			if((mp->lookupflags & DO_OPEN) ||
			   (IS_DIR(&entry) && 
			    (mp->lookupflags & DO_OPEN_DIRS))) {
				MyFile = mp->File = OpenFileByDirentry(&entry);
			}
			if(got_signal)
				break;
			mp->direntry = &entry;
			if(IS_DIR(&entry))
				ret |= mp->dirCallback(&entry,mp);
			else
				ret |= mp->callback(&entry, mp);
			FREE(&MyFile);
		}
		if (fat_error(Dir))
			ret |= ERROR_ONE;
		if(mp->fast_quit && (ret & ERROR_ONE))
			break;
	}
	if (r == -2)
	    return ERROR_ONE;
	if(got_signal)
		ret |= ERROR_ONE;
	return ret;
}
Example #17
0
int fs_getdents(int fd, char *buf, size_t n)
{
    unsigned int i, pos;
    struct inode_s *dir, *ino;
    struct dir_entry_s dentry;
    struct dirent *dent;
    struct file_s *flip;

    flip = get_file(fd);
    dir = flip->f_ino;

    if (!IS_DIR(dir->i_mode))
        return ERROR;

    i = 0;
    pos = flip->f_pos;
    while (n >= sizeof(struct dirent) + 1) {
        if (next_entry(dir, &pos, &dentry) == ERROR)
            break;
        ino = get_inode(dentry.num);
        dent = (struct dirent *) (buf + i);
        dent->d_ino = dentry.num; 
        dent->d_off = pos - sizeof(struct dir_entry_s);
        dent->d_reclen = mystrncpy(dent->d_name, dentry.name, MAX_NAME) + 
                         1 +                      /* add the \0 */
                         sizeof(ino_t) +          /* add the d_ino */
                         sizeof(off_t) +          /* add the d_off */
                         sizeof(unsigned short) + /* add the d_reclen */
                         1;                       /* add the d_type */
        /* add d_type */
        *(buf + i + dent->d_reclen - 1) = (IS_DIR(ino->i_mode) ? DT_DIR :
                                          IS_FILE(ino->i_mode) ? DT_REG :
                                          IS_CHAR(ino->i_mode) ? DT_CHR :
                                                                 DT_UNK);
        i += dent->d_reclen;
        n -= dent->d_reclen;
        release_inode(ino);
    }
    flip->f_pos = pos;

    return i;
}
bool QFileSystemModelEx::hasSubfolders(const QString &path)
{
	if(s_findFirstFileExInfoLevel == INT_MAX)
	{
		const lamexp_os_version_t &osVersionNo = lamexp_get_os_version();
		s_findFirstFileExInfoLevel = (osVersionNo >= lamexp_winver_win70) ? FindExInfoBasic : FindExInfoStandard;
	}

	WIN32_FIND_DATAW findData;
	bool bChildren = false;

	HANDLE h = FindFirstFileEx(QWCHAR(QDir::toNativeSeparators(path + "/*")), ((FINDEX_INFO_LEVELS)s_findFirstFileExInfoLevel), &findData, FindExSearchLimitToDirectories, NULL, 0);

	if(h != INVALID_HANDLE_VALUE)
	{
		if(NO_DOT_OR_DOTDOT(findData.cFileName))
		{
			bChildren = IS_DIR(findData.dwFileAttributes);
		}
		while((!bChildren) && FindNextFile(h, &findData))
		{
			if(NO_DOT_OR_DOTDOT(findData.cFileName))
			{
				bChildren = IS_DIR(findData.dwFileAttributes);
			}
		}
		FindClose(h);
	}
	else
	{
		DWORD err = GetLastError();
		if((err == ERROR_NOT_SUPPORTED) || (err == ERROR_INVALID_PARAMETER))
		{
			qWarning("FindFirstFileEx failed with error code #%u", err);
		}
	}

	return bChildren;
}
Example #19
0
static int del_file(direntry_t *entry, MainParam_t *mp)
{
	char shortname[13];
	direntry_t subEntry;
	Stream_t *SubDir;
	Arg_t *arg = (Arg_t *) mp->arg;
	MainParam_t sonmp;
	int ret;
	int r;	

	sonmp = *mp;
	sonmp.arg = mp->arg;

	r = 0;
	if (IS_DIR(entry)){
		/* a directory */		
		SubDir = OpenFileByDirentry(entry);
		initializeDirentry(&subEntry, SubDir);
		ret = 0;
		while((r=vfat_lookup(&subEntry, "*", 1,
				     ACCEPT_DIR | ACCEPT_PLAIN,
				     shortname, NULL)) == 0 ){
			if(shortname[0] != DELMARK &&
			   shortname[0] &&
			   shortname[0] != '.' ){
				if(arg->deltype != 2){
					fprintf(stderr,
						"Directory ");
					fprintPwd(stderr, entry,0);
					fprintf(stderr," non empty\n");
					ret = ERROR_ONE;
					break;
				}
				if(got_signal) {
					ret = ERROR_ONE;
					break;
				}
				ret = del_file(&subEntry, &sonmp);
				if( ret & ERROR_ONE)
					break;
				ret = 0;
			}
		}
		FREE(&SubDir);
		if (r == -2)
			return ERROR_ONE;
		if(ret)
			return ret;
	}
	return del_entry(entry, mp);
}
Example #20
0
static int fatfs_lookup(void *priv, const char *name, struct vfs_node *dir)
{
    struct fatfs_dirent *dirent = (struct fatfs_dirent *)priv;
    struct fatfs_priv   *fsop   = dirent->fs;

    size_t bytes_per_cluster = (fsop->bytes_per_sector * fsop->sectors_per_cluster);
    char *cluster_buffer = (char *)malloc(bytes_per_cluster);

    if (dirent->flag & 0xFF00) {
        return fatfs_root(fsop, name, dir);
    }else if (!IS_DIR(dirent->flag)) {
        return -1;
    }

    size_t valid_cluster = dirent->entry;
    size_t dpcnt = bytes_per_cluster / 32;
    struct fat_entry *dirents, entry;
    dirents = (struct fat_entry *)cluster_buffer;
    
    struct fat_opvector *opv = fsop->opvector;
    while (valid_cluster < opv->fat_max_cluster) {
        size_t cluster;
        if (-1 == fat_read_cluster(fsop, valid_cluster, cluster_buffer)) {
            free(cluster_buffer);
            return -1;
        }

        if (0 == fat_dirent_lookup(dirents, dpcnt, name, &entry)) {
            VFS_MALLOC(struct fatfs_dirent, dirent);
            dirent->length = entry.length;
            dirent->entry  = entry.cluster_entry| (entry.cluster_high << 16);
            dirent->entry &= opv->fat_cluster_mask;
            printf("found: %d\n", dirent->entry);
            dirent->flag   = entry.attribute;
            dirent->fs = fsop;
            dir->vops = &fatfs_vops;
            dir->priv = dirent;
            free(cluster_buffer);
            return 0;
        }
        
        if (-1 == (*opv->fat_next_cluster)(fsop, valid_cluster, &cluster)) {
            free(cluster_buffer);
            return -1;
        }
        valid_cluster = cluster;
    }

    free(cluster_buffer);
    return -1;
}
Example #21
0
int sys_chdir(const char *name)
{
	if (!current_task) return -EGENERIC;
	if (!access_ok(VERIFY_READ, name, VERIFY_STRLEN)) return -EFAULT;
	int status;
	vnode *node = namei(name, &status);

	if (node) {
		if (IS_DIR(node))
			current_task->pwd = node;
		else return -ENOTDIR;
	} else return status;
	return 0;
}
Example #22
0
/*
 * Lookup the parent inode 
 *
 * NOTE: the parent should  be directory!
 */
struct inode *namei_parent(const char *pathname)
{
	struct inode *dir = namei(pathname, LOOKUP_PARENT);
	
	if (!IS_ERR_OR_NULL(dir))
		return dir ? ERR_CAST(dir) : ERR_PTR(-ENOENT);
	
	if (!IS_DIR(dir)) {
		free_inode(dir);
		return ERR_PTR(-ENOTDIR);
	}

	return dir;
}
Example #23
0
int print_conflicts(struct hash *hash)
{
    int i;
    struct tree_node *t, *s;
    char *pkgname;

    for (i = 0; i < TBLSIZE; i++) {
        t = tree_first(hash->tbl[i]->root);

        while (t) {
            if (!IS_FILE(t->n->name) || IS_DIR(t->n)
                || tree_count(t->n->providedby) < 2) {
                t = tree_next(t);
                continue;
            }

            printf("%s: ", t->n->name);

            s = tree_first(t->n->providedby->root);

            while (s) {
                if (IS_PKG(s->n)) {
                    printf("%s", s->n->name);
                } else if (is_virtual_file(s->n->name)) {
                    pkgname = get_pkgname(s->n->name);
                    printf("%s", pkgname);
                    free(pkgname);
                } else {
                    fprintf(stderr, "bee-dep: print_conflicts: "
                            "could not get pkgname for \"%s\"\n",
                            s->n->name);
                    return 1;
                }

                s = tree_next(s);

                if (!s)
                    puts("");
                else
                    printf(" ");
            }

            t = tree_next(t);
        }
    }

    return 0;
}
Example #24
0
/*===========================================================================*
 *				write_file				     *
 *===========================================================================*/
static ssize_t write_file(struct inode *ino, off_t pos, size_t count,
	struct fsdriver_data *data)
{
/* Write data or zeroes to a file, depending on whether a valid pointer to
 * a data grant was provided.
 */
  size_t size, off, chunk;
  char *ptr;
  int r;

  if (pos < 0)
	return EINVAL;

  assert(!IS_DIR(ino));

  if ((r = get_handle(ino)) != OK)
	return r;

  assert(count > 0);

  /* Use the buffer from below to eliminate extra copying. */
  size = sffs_table->t_writebuf(&ptr);
  off = 0;

  while (count > 0) {
	chunk = MIN(count, size);

	if (data != NULL) {
		if ((r = fsdriver_copyin(data, off, ptr, chunk)) != OK)
			break;
	} else {
		/* Do this every time. We don't know what happens below. */
		memset(ptr, 0, chunk);
	}

	if ((r = sffs_table->t_write(ino->i_file, ptr, chunk, pos)) <= 0)
		break;

	count -= r;
	off += r;
	pos += r;
  }

  if (r < 0)
	return r;

  return off;
}
Example #25
0
/*===========================================================================*
 *				do_lookup				     *
 *===========================================================================*/
int do_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node,
	int *is_mountpt)
{
/* Resolve a path string to an inode.
 */
  struct inode *dir_ino, *ino;
  struct sffs_attr attr;
  char path[PATH_MAX];
  int r;

  dprintf(("%s: lookup: got query for %"PRIu64", '%s'\n",
	sffs_name, dir_nr, name));

  if ((dir_ino = find_inode(dir_nr)) == NULL)
	return EINVAL;

  attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE;

  if ((r = verify_inode(dir_ino, path, &attr)) != OK)
	return r;

  if (!IS_DIR(dir_ino))
	return ENOTDIR;

  r = OK;
  if (!strcmp(name, "."))
	get_inode(ino = dir_ino);
  else if (!strcmp(name, ".."))
	r = go_up(path, dir_ino, &ino, &attr);
  else
	r = go_down(path, dir_ino, name, &ino, &attr);

  if (r != OK)
	return r;

  node->fn_ino_nr = INODE_NR(ino);
  node->fn_mode = get_mode(ino, attr.a_mode);
  node->fn_size = attr.a_size;
  node->fn_uid = sffs_params->p_uid;
  node->fn_gid = sffs_params->p_gid;
  node->fn_dev = NO_DEV;

  *is_mountpt = FALSE;

  return OK;
}
Example #26
0
/* rename oldpath to newpath */
int fs_rename(const char *oldpath, const char *newpath)
{
    struct inode_s *dir, *last_dir, *ino;
    char path[MAX_PATH], name[MAX_NAME];

    dir = last_dir = ino = NULL;

    /* get last component of path */
    process_path(newpath, path, name);
    if (name[0] == '\0') {
        char tmp[MAX_PATH];
        process_path(oldpath, tmp, name);
    }

    dir = current_dir();
    /* get last directory of target path */
    if ( (last_dir = find_inode(dir, path, FS_SEARCH_GET)) == NULL)
        goto err;

    /* remove entry from the old directory */
    if ( (ino = find_inode(dir, oldpath, FS_SEARCH_REMOVE)) == NULL)
        goto err;

    /* new entry in the last directory of path (or old one if file exists) */
    if (add_entry(last_dir, ino->i_num, name) == ERROR)
        goto err;

    /* check if oldpath was a dir, and update '..' in that case */
    if (IS_DIR(ino->i_mode)) {
        add_entry(ino, last_dir->i_num, "..");
        last_dir->i_nlinks++;
    }

    release_inode(last_dir);
    release_inode(dir);
    release_inode(ino);

    return OK;

err:
    release_inode(last_dir);
    release_inode(dir);
    release_inode(ino);

    return ERROR;
}
Example #27
0
/*******************************************************************************
* estimateIsoSize()
* Recursive
* Estimate the size of the directory trees + file contents on the iso
* */
bk_off_t estimateIsoSize(const BkDir* tree, int filenameTypes)
{
    bk_off_t estimateDrSize;
    bk_off_t thisDirSize;
    int numItems; /* files and directories */
    BkFileBase* child;
    
    thisDirSize = 0;
    numItems = 0;
    
    child = tree->children;
    while(child != NULL)
    {
        if(IS_DIR(child->posixFileMode))
        {
            thisDirSize += estimateIsoSize(BK_DIR_PTR(child), filenameTypes);
        }
        else if(IS_REG_FILE(child->posixFileMode))
        {
            if(BK_FILE_PTR(child)->location == NULL ||
               !BK_FILE_PTR(child)->location->alreadyCounted)
            {
                thisDirSize += BK_FILE_PTR(child)->size;
                thisDirSize += BK_FILE_PTR(child)->size % NBYTES_LOGICAL_BLOCK;
            }
            if(BK_FILE_PTR(child)->location != NULL)
                BK_FILE_PTR(child)->location->alreadyCounted = true;
        }
        
        numItems++;
        
        child = child->next;
    }
    
    estimateDrSize = 70;
    if(filenameTypes & FNTYPE_JOLIET)
        estimateDrSize += 70;
    if(filenameTypes & FNTYPE_ROCKRIDGE)
        estimateDrSize += 70;
    
    thisDirSize += 68 + (estimateDrSize * numItems);
    thisDirSize += NBYTES_LOGICAL_BLOCK - (68 + (estimateDrSize * numItems)) % NBYTES_LOGICAL_BLOCK;
    
    return thisDirSize;
}
Example #28
0
File: read.c Project: Hooman3/minix
/*===========================================================================*
 *				do_read					     *
 *===========================================================================*/
ssize_t do_read(ino_t ino_nr, struct fsdriver_data *data, size_t count,
	off_t pos, int call)
{
/* Read data from a file.
 */
  struct inode *ino;
  size_t size, off;
  char *ptr;
  int r, chunk;

  if ((ino = find_inode(ino_nr)) == NULL)
	return EINVAL;

  if (IS_DIR(ino)) return EISDIR;

  if ((r = get_handle(ino)) != OK)
	return r;

  assert(count > 0);

  /* Use the buffer from below to eliminate extra copying. */
  size = sffs_table->t_readbuf(&ptr);
  off = 0;

  while (count > 0) {
	chunk = MIN(count, size);

	if ((r = sffs_table->t_read(ino->i_file, ptr, chunk, pos)) <= 0)
		break;

	chunk = r;

	if ((r = fsdriver_copyout(data, off, ptr, chunk)) != OK)
		break;

	count -= chunk;
	off += chunk;
	pos += chunk;
  }

  if (r < 0)
	return r;

  return off;
}
Example #29
0
//遍历文件夹的驱动函数
void List_Files(const char *path, int recursive)
{
          int len;
          char temp[256];
          //去掉末尾的'/'
          len = strlen(path);
          strcpy(temp, path);
          if(temp[len - 1] == '/') temp[len -1] = '\0';

          if(IS_DIR(temp))
          {
                   //处理目录
                   List_Files_Core(temp, recursive);
          }
         else   //输出文件
         {
                  printf("%s\n", path);
         }
}
Example #30
0
/*===========================================================================*
 *				do_write				     *
 *===========================================================================*/
ssize_t do_write(ino_t ino_nr, struct fsdriver_data *data, size_t count,
	off_t pos, int call)
{
/* Write data to a file.
 */
  struct inode *ino;

  if (state.s_read_only)
	return EROFS;

  if ((ino = find_inode(ino_nr)) == NULL)
	return EINVAL;

  if (IS_DIR(ino)) return EISDIR;

  if (count == 0) return 0;

  return write_file(ino, pos, count, data);
}