file_system_t *init_ramfs( void ){ DEBUG_HERE ramfs_file_header_t *ramfs_root; ramfs_header_t *head = knew( ramfs_header_t ); file_system_t *ret = knew( file_system_t ); head->ramfs_files = knew( ramfs_file_header_t ); ramfs_root = head->ramfs_files; head->ramfs_i_count = 1; memcpy( ramfs_root->name, "root", 5 ); ramfs_root->type = FS_DIR; ramfs_root->mask = 0777; ramfs_root->inode = head->ramfs_i_count++; ramfs_root->size = 0; ramfs_root->links = 1; ret->name = "ramfs"; ret->i_root = ramfs_root->inode; ret->fs_data = head; ret->ops = &ramfs_file_funcs; return ret; }
ext2_device_t *ext2_create_device( char *path ){ ext2_device_t *ret = knew( ext2_device_t ); ret->fd = open( path, O_RDONLY ); if ( ret->fd < 0 ){ printf( "[ext2] Could not open file\n" ); return 0; } ret->sprblk = knew( char[1024] ); ret->esprblk = (ext2_ex_sprblk_t *)((unsigned long)ret->sprblk + 84); lseek( ret->fd, 1024, 0 ); read( ret->fd, ret->sprblk, 1024 ); ret->block_size = ( 1024 << ret->sprblk->block_size ); ret->block_groups = ret->sprblk->n_blocks / ret->sprblk->n_block_block_grp; ret->block_groups += ( ret->sprblk->n_blocks % ret->sprblk->n_block_block_grp != 0 )?1:0; ret->blkdesc = knew( ext2_block_desc_t[ ret->block_groups ]); lseek( ret->fd, ret->block_size * 2, 0 ); read( ret->fd, ret->blkdesc, sizeof( ext2_block_desc_t ) * ret->block_groups ); return ret; }
file_node_t *ext2_create( char *path ){ file_node_t *ret = knew( file_node_t ); ret->fs = knew( file_system_t ); ret->fs->fs_data = ext2_create_device( path ); ret->inode = 2; //ret->parent = ret; //memcpy( ret->name, "root", 5 ); return ret; }
void set_fs_root( file_system_t *new_root ){ if ( !fs_root ) fs_root = knew( file_node_t ); fs_root->inode = new_root->i_root; fs_root->fs = new_root; }
int ramfs_mknod( file_node_t *node, char *name, int mode, int dev ){ DEBUG_HERE ramfs_header_t *head = node->fs->fs_data; ramfs_file_header_t *filehead = ramfs_get_file_h( head, node->inode ); ramfs_file_header_t *temp, *move; printf( "[ ] Here from ramfs_mknod... 0x%x\n", head ); unsigned long ramfs_i_count = head->ramfs_i_count; if ( filehead->type != FS_DIR ) return -1; ramfs_mkdir_entry( node, name, head->ramfs_i_count ); temp = knew( ramfs_file_header_t ); temp->mask = mode; temp->inode = ramfs_i_count; temp->type = dev; temp->size = 0; temp->parent = node; temp->links = 1; memcpy( head->ramfs_files[ ramfs_i_count ].name, name, strlen( name ) + 1 ); for ( move = filehead; move->next; move = move->next ); move->next = temp; head->ramfs_i_count++; return 0; }
int ramfs_mkdir( file_node_t *node, char *name, int mode ){ DEBUG_HERE ramfs_header_t *head = node->fs->fs_data; ramfs_file_header_t *filehead = ramfs_get_file_h( head, node->inode ); ramfs_file_header_t *temp, *move; unsigned long ramfs_i_count = head->ramfs_i_count; if ( filehead->type != FS_DIR ) return -1; ramfs_mkdir_entry( node, name, head->ramfs_i_count ); temp = knew( ramfs_file_header_t ); temp->mask = mode; temp->type = FS_DIR; temp->inode = ramfs_i_count; temp->parent = node; temp->links = 1; temp->data = 0; memcpy( head->ramfs_files[ head->ramfs_i_count ].name, name, strlen( name + 1 )); for ( move = filehead; move->next; move = move->next ); move->next = temp; head->ramfs_i_count++; return 0; }
int check_perms( task_t *task, file_node_t *node, int flags ){ int perms = 0000; int good_op = 1; file_info_t *n_info = knew( file_info_t ); node->fs->ops->get_info( node, n_info ); if ( task->uid == n_info->uid ){ perms = n_info->mask >> P_USHIFT & 07; } else if ( task->gid == n_info->gid ){
int ramfs_mkdir_entry( file_node_t *node, char *name, int inode ){ ramfs_file_header_t *filehead = ramfs_get_file_h( node->fs->fs_data, node->inode ); if ( filehead->type != FS_DIR ) return -1; //struct dirent *dir; char *file_data = filehead->data; ramfs_dirent_t *dir, *temp = 0; int nlen = strlen( name ) + 1; unsigned int dsize = sizeof( struct dirent ) + nlen; ramfs_header_t *head = node->fs->fs_data; dir = knew( ramfs_dirent_t ); printf( "doot" ); dir->inode = inode; dir->size = dsize; dir->name_len = nlen; dir->name = knew( char[ strlen( name )]); memcpy( dir->name, name, nlen ); printf( "deet" ); if ( !filehead->data ){ filehead->data = dir; } else { printf( "diit" ); for ( temp = (ramfs_dirent_t *)file_data; temp->next; temp = temp->next ); temp->next = dir; } filehead->size += dir->size; printf( "daat\n" ); return 0; }
int fatfs_vfs_lookup( struct file_node *node, struct file_node *buf, char *name, int flags ){ int ret = -ERROR_NOT_FOUND; fatfs_device_t *dev = node->fs->devstruct; unsigned cluster_size; //char namebuf[256]; char *namebuf; uint8_t *sectbuf; int i; int has_longname = 0; fatfs_dirent_t *dirbuf; fatfs_dircache_t *dircache; fatfs_dircache_t *newcache; fatfs_longname_ent_t *longentbuf; dircache = hashmap_get( dev->inode_map, node->inode ); if ( dircache ){ namebuf = knew( char[ 256 ]); if ( dircache->dir.attributes & FAT_ATTR_DIRECTORY ){ cluster_size = dev->bpb->bytes_per_sect * dev->bpb->sect_per_clus; sectbuf = knew( uint8_t[cluster_size] ); dirbuf = (void *)sectbuf; VFS_FUNCTION(( &dev->device_node ), read, sectbuf, cluster_size, dev->bpb->bytes_per_sect * node->inode ); for ( i = 0; i < dev->bpb->dirents; i++ ){ if ( *(char *)(dirbuf + i) == 0 || *(char *)(dirbuf + i) == 0xe5 ) continue; if ( dirbuf[i].attributes == FAT_ATTR_LONGNAME ){ longentbuf = (void *)(dirbuf + i); fatfs_apply_longname( longentbuf, namebuf, 256 ); has_longname = 1; } else { char *fname = has_longname? namebuf : (char *)dirbuf[i].name; if ( strcmp( name, fname ) == 0 ){ // Found it, cool newcache = knew( fatfs_dircache_t ); memcpy( &newcache->dir, dirbuf + i, sizeof( fatfs_dirent_t )); newcache->references = 0; buf->inode = fatfs_relclus_to_sect( dev, newcache->dir.cluster_low ); buf->fs = node->fs; buf->mount = 0; if ( hashmap_get( dev->inode_map, buf->inode ) == 0 ) hashmap_add( dev->inode_map, buf->inode, newcache ); ret = 0; break; } has_longname = 0; namebuf[0] = 0; } } kfree( sectbuf ); } else { ret = -ERROR_NOT_DIRECTORY; } kfree( namebuf ); } else {