Example #1
0
int fs_delete(FileSystem *fs, const char *f, int pos, int l) {
    Inode *inode = NULL;
    char *data = NULL;
    File *file = NULL;
    int i = 0;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    data = (char *) malloc(inode->filesize);
    if (!data) return ERROR;
    file = file_new(fs, inode);
    file_get_contents(file, data);
    file_free(&file);
    if (pos + l > inode->filesize) {
        l = inode->filesize - pos;
    }
    for (i = pos + l; i < inode->filesize; ++i) {
        data[i - l] = data[i];
    }
    file = file_new(fs, inode);
    file_put_contents(file, data, inode->filesize - l);
    file_free(&file);
    free(data);
    return OK;
}
Example #2
0
void *folder_new(t_symbol *s, short ac, t_atom *av)
{
	t_folder *x;
	
	x = object_alloc(folder_class);
	x->f_countout = intout((t_object *)x);
	outlet_new((t_object *)x,0);
	x->f_input = 0;
	x->f_numtypes = 0;
	x->f_path = 0;
	x->f_outcount = 0;
	if (ac) {
		if (atom_gettype(av) == A_SYM)
		{
			x->f_input = atom_getsym(av);
		}
		if (ac > 1) {
			av++;
			folder_types(x,s,ac-1,av); // ddz 06/27/05 ac -> ac-1 bug fix
		}
	}
	if (!x->f_numtypes) {
		short numtypes;
		
		typelist_make(x->f_types, TYPELIST_MAXFILES, &numtypes);
		x->f_numtypes = numtypes;
	}
	if (x->f_input)
		folder_lookup(x);		
	return x;
}
Example #3
0
int fs_unlink(FileSystem *fs, const char *f) {
    Inode *inode = NULL;
    char ppath[4096] = "";
    char cname[4096] = "";
    Folder *pfd = NULL;
    
    if (ERROR == fs_write(fs, f, 0, "")) return ERROR;
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    freelist_release(fs->freelist, inode->page_num);
    fs_split_path(f, ppath, cname);
    pfd = folder_open(fs, folder_lookup(fs, fs->cur, ppath));
    folder_remove_child(pfd, cname);
    folder_close(&pfd);
    return OK;
}
Example #4
0
int fs_insert(FileSystem *fs, const char *f, int pos, int l, const char *data) {
    Inode *inode = NULL;
    char *buffer = NULL;
    File *file = NULL;
    int i = 0;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    buffer = (char *) malloc(inode->filesize + l);
    if (!buffer) return ERROR;
    file = file_new(fs, inode);
    file_get_contents(file, buffer);
    file_free(&file);
    if (pos > inode->filesize) {
        pos = inode->filesize;
    }
    for (i = inode->filesize - 1; i >= pos; --i) {
        buffer[i + l] = buffer[i];
    }
    memcpy(buffer + pos, data, l);
    file = file_new(fs, inode);
    file_put_contents(file, buffer, inode->filesize + l);
    file_free(&file);
    free(buffer);
    return OK;
}
Example #5
0
int fs_rmdir(FileSystem *fs, const char *d) {
    // TODO what if there are children in this directory?
    Inode *inode = NULL;
    char ppath[4096] = "";
    char cname[4096] = "";
    Folder *pfd = NULL;
    
    if (ERROR == fs_write(fs, d, 0, "")) return ERROR;
    inode = folder_lookup(fs, fs->cur, d);
    if (!inode) return ERROR;
    freelist_release(fs->freelist, inode->page_num);
    fs_split_path(d, ppath, cname);
    pfd = folder_open(fs, folder_lookup(fs, fs->cur, ppath));
    folder_remove_child(pfd, cname);
    folder_close(&pfd);
    return OK;
}
Example #6
0
int fs_chdir(FileSystem *fs, const char *path) {
    Inode *inode = NULL;
    
    inode = folder_lookup(fs, fs->cur, path);
    if (!inode) return ERROR;
    fs->cur = inode;
    return OK;
}
Example #7
0
int fs_write(FileSystem *fs, const char *f, int l, const char *data) {
    Inode *inode = NULL;
    File *file = NULL;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    file = file_new(fs, inode);
    file_put_contents(file, data, l);
    file_free(&file);
    return OK;
}
Example #8
0
void folder_action(t_folder *x)
{
	x->f_outcount = 0;
	if (x->f_path == 0) {
		folder_lookup(x);
		if (x->f_path == 0)
			goto bag;
	}
	folder_enumerate(x);
bag:
	outlet_int(x->f_countout,x->f_outcount);
}
Example #9
0
int fs_isdir(FileSystem *fs, const char *d) {
    Inode *inode = NULL;
    
    inode = folder_lookup(fs, fs->cur, d);
#ifdef DEBUG
    fprintf(stderr, "fs_isdir inode=%p\n", inode);
    if (inode) {
        fprintf(stderr, "INODE_FILE=%d, INODE_FOLDER=%d\n", INODE_FILE, INODE_FOLDER);
        fprintf(stderr, "fs_isdir inode->type=%d\n", inode->type);
    }
#endif
    return inode && inode->type == INODE_FOLDER;
}
Example #10
0
void fs_cat(FileSystem *fs, const char *f, FILE *fp) {
    Inode *inode = NULL;
    char *data = NULL;
    File *file = NULL;
    
    inode = folder_lookup(fs, fs->cur, f);
    data = (char *) malloc(inode->filesize);
    file = file_new(fs, inode);
    file_get_contents(file, data);
    file_free(&file);
    fprintf(fp, "%s\n", data);
    fflush(fp);
    free(data);
}
Example #11
0
int fs_mkdir(FileSystem *fs, const char *d) {
    int p = 0;
    Inode *inode = NULL;
    Folder *fd = NULL;
    char ppath[4096] = "";
    char cname[4096] = "";
    Folder *pfd = NULL;
    int parent_page_num = 0;
    
    p = freelist_allocate(fs->freelist);
    if (p <= 1) return ERROR;
    inode = inode_new(p);
    if (!inode) return ERROR;
    inode->type = INODE_FOLDER;
    inode->filesize = 0;
    inode->lastmod = time(NULL);
    inode->firstpage = 0;
    fs_save_inode(fs, inode);
    inode_free(&inode);
    
    fs_split_path(d, ppath, cname);
#ifdef DEBUG
    fprintf(stderr, "fs_mkdir, d=`%s`, ppath=`%s`, cname=`%s`\n", d, ppath, cname);
#endif
    
    pfd = folder_open(fs, folder_lookup(fs, fs->cur, ppath));
    parent_page_num = AS_FILE(pfd)->inode->page_num;
    folder_add_child(pfd, cname, p);
    folder_close(&pfd);
    
    fd = folder_open(fs, fs_load_inode(fs, p));
    fs_split_path(d, ppath, cname);
    folder_add_child(fd, "", ROOT_PAGE_NUM());
    folder_add_child(fd, ".", p);
    folder_add_child(fd, "..", parent_page_num);
    folder_close(&fd);
    return OK;
}
Example #12
0
int fs_create(FileSystem *fs, const char *f) {
    int p = 0;
    Inode *inode = NULL;
    char ppath[4096] = "";
    char cname[4096] = "";
    Folder *pfd = NULL;
    
    p = freelist_allocate(fs->freelist);
    if (p <= 1) return ERROR;
    inode = inode_new(p);
    if (!inode) return ERROR;
    inode->type = INODE_FILE;
    inode->filesize = 0;
    inode->firstpage = 0;
    fs_save_inode(fs, inode);
    inode_free(&inode);
    
    fs_split_path(f, ppath, cname);
    pfd = folder_open(fs, folder_lookup(fs, fs->cur, ppath));
    folder_add_child(pfd, cname, p);
    folder_close(&pfd);
    return OK;
}
Example #13
0
int fs_isfile(FileSystem *fs, const char *f) {
    Inode *inode = NULL;
    
    inode = folder_lookup(fs, fs->cur, f);
    return inode && inode->type == INODE_FILE;
}
Example #14
0
int fs_exists(FileSystem *fs, const char *f) {
    return NULL != folder_lookup(fs, fs->cur, f);
}