diff options
| author | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
| commit | e3a8099343aac9d94f411638ad84632d4b620132 (patch) | |
| tree | f0a1f73ab106c17b25fd8a5264a66b6b48e55e48 /fs | |
| parent | f35d2124c36f8d39a953b76620e081b79c2faffd (diff) | |
cleanup sys/ etc
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/ext2.c | 29 | ||||
| -rw-r--r-- | fs/ext2.h | 6 | ||||
| -rw-r--r-- | fs/mount.c | 28 | ||||
| -rw-r--r-- | fs/mount.h | 6 | ||||
| -rw-r--r-- | fs/sysfs.c | 6 |
5 files changed, 47 insertions, 28 deletions
@@ -11,7 +11,7 @@ #include "lib/string/string.h" -#include "interface/fs.h" +#include <sys/dirent.h> // THE SUPERBLOCK typedef struct ext2_superblock_struct @@ -226,26 +226,27 @@ static uint32_t ext2_filename_to_inode_traverse(uint32_t ext2_start_addr, char * uint32_t pos=0; while(1) { - fs_dirent dirs; + struct dirent dirs; uint32_t ret=ext2_read_dir(VMEM_EXT2_RAMIMAGE,inode_start, &dirs,&pos); if(!ret)break; - if(strlen(dirs.name)==len && !strcmp_l(first,dirs.name,len)) + if(strlen(dirs.d_name)==len && !strcmp_l(first,dirs.d_name,len)) { - klog("found inode %d %s%s (in inode %d)",dirs.inode,dirs.name,dirs.type==FS_FILE_TYPE_DIR?"/ ":" ",inode_start); - if(final)return dirs.inode; - return ext2_filename_to_inode_traverse(ext2_start_addr,&path[len]+1,dirs.inode); +// klog("found inode %d %s%s (in inode %d)",dirs.d_ino,dirs.d_name,dirs.type==FS_FILE_TYPE_DIR?"/ ":" ",inode_start); + if(final)return dirs.d_ino; + return ext2_filename_to_inode_traverse(ext2_start_addr,&path[len]+1,dirs.d_ino); } } - klog("file not found! : %s",path); return 0; } uint32_t ext2_filename_to_inode(uint32_t ext2_start_addr, char *path) { if(!strcmp_l(path,"/",0))return 2; // root is inode 2 by definition - return ext2_filename_to_inode_traverse(ext2_start_addr,path,2); + uint32_t ret= ext2_filename_to_inode_traverse(ext2_start_addr,path,2); + if(ret==0)klog("file not found! : %s",path); + return ret; } uint32_t ext2_read_inode(uint32_t ext2_start_addr, int inode_nr, char *buf, uint32_t *pos, uint32_t max_size) @@ -273,7 +274,7 @@ uint32_t ext2_read_inode(uint32_t ext2_start_addr, int inode_nr, char *buf, uint return count; } -int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, fs_dirent *dirs, uint32_t *pos) +int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, struct dirent *dirs, uint32_t *pos) { ext2_superblock *super=ext2_check(ext2_start_addr); ext2_inode *inode=ext2_get_inode(ext2_start_addr,inode_nr); @@ -293,10 +294,10 @@ int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, fs_dirent *dirs, uint3 dirs->type=FS_FILE_TYPE_FILE; ext2_inode *inode_current=ext2_get_inode(ext2_start_addr,dir->inode); if(inode_current->permissions&0x4000)dirs->type=FS_FILE_TYPE_DIR; - memcpy(dirs->name,ptr+8,dir->name_length_low); - if(dir->name_length_low>255)dirs->name[255]=0; - dirs->name[dir->name_length_low]=0; // null temrinate - dirs->inode=dir->inode; + memcpy(dirs->d_name,ptr+8,dir->name_length_low); + if(dir->name_length_low>255)dirs->d_name[255]=0; + dirs->d_name[dir->name_length_low]=0; // null temrinate + dirs->d_ino=dir->inode; *pos+=dir->size; return 1; @@ -314,7 +315,7 @@ fd ext2_mount_file_open(mount *m,char *path) return fd_from_path(path); } -int ext2_mount_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) +int ext2_mount_read_dir(mount *m,char *path, struct dirent *dirs, uint32_t *pos) { uint32_t inode= ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE,path); if(inode==0)return -1; @@ -15,7 +15,7 @@ */ #include <stdint.h> -#include "interface/fs.h" +#include <sys/dirent.h> /** klog some basic info about the ext2 fs */ void ext2_dump_info(uint32_t ext2_start_addr); @@ -25,9 +25,9 @@ uint32_t ext2_read_inode(uint32_t ext2_start_addr, int inode_nr, char *buf, uint /** Simiilar to ext2_read_inode but for directory inodes. * the inode number needs to point to a directory inode - * fills on fs_dirent and sets _pos_ to the position of the next + * fills on dirent and sets _pos_ to the position of the next */ -int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, fs_dirent *dirs, uint32_t *pos); +int ext2_read_dir(uint32_t ext2_start_addr, int inode_nr, struct dirent *dirs, uint32_t *pos); /** get inode number from file path / if not found return 0 */ uint32_t ext2_filename_to_inode(uint32_t ext2_start_addr, char *path); @@ -49,6 +49,7 @@ static uint32_t check_match(char *p1, char *p2) c++; p1++; p2++; + if(*p1=='/')return c; } } @@ -71,9 +72,9 @@ static char* get_mount_for_path(char *path,mount *mnt) for(int i=0;i<mounts_count;i++) { mount *m=&mounts[i]; - uint32_t len=check_match(path,m->path); + uint32_t len=check_match(path+1,(m->path)+1); - if(len>best_len)//&&len==strlen(m->path)) + if(len>best_len&&path[len-1]=='/')//&&len==strlen(m->path)) { best=i; best_len=len; @@ -89,8 +90,25 @@ fd mount_file_open(char *path) mount m; char buf[256]; if(path[0]!='/'){ - // TODO: use environemnet PWD var! - sprintf(buf,"/home/miguel/%s",path); + + // we extract the PWD env variable! + // TODO: this is ugly! + char **env1=VMEM_USER_ENV+1024*2; + + int i=0; + while(1) + { + if(env1[i]==0)kpanic("unable to extract PWD!"); + if(!strcmp_l("PWD=",env1[i],4)) + { + sprintf(buf,"%s/%s",env1[i]+4,path); + klog("absolute path exracted: %s",buf); + break; + } + i++; + } + + } else { @@ -101,7 +119,7 @@ fd mount_file_open(char *path) return m.mount_file_open(&m,p); } -int mount_read_dir (char *path, fs_dirent *dirs, uint32_t *pos) +int mount_read_dir (char *path, struct dirent *dirs, uint32_t *pos) { mount m; char *p=get_mount_for_path(path,&m); @@ -19,7 +19,7 @@ #include <stdint.h> -#include "interface/fs.h" // provides fs_dirent structure for read_dir() +#include <sys/dirent.h> // provides fs_dirent structure for read_dir() #include "fd.h" // file descriptor returned by open /** the possible values for mount_struct.type */ @@ -36,7 +36,7 @@ typedef struct mount_struct char path[256]; // where are we mounted (provide leading and trailing slash!) fd (*mount_file_open)(struct mount_struct*, char *path); - int (*mount_read_dir) (struct mount_struct*, char *path, fs_dirent *dirs, uint32_t *pos); + int (*mount_read_dir) (struct mount_struct*, char *path, struct dirent *dirs, uint32_t *pos); void *data; // pointer to some opaque private data @@ -49,7 +49,7 @@ void mount_add(mount mnt); fd mount_file_open(char *path); /** TODO: should use fd number instead of PATH on each call*/ -int mount_read_dir (char *path, fs_dirent *dirs, uint32_t *pos); +int mount_read_dir (char *path, struct dirent *dirs, uint32_t *pos); /** sysfs interface / exposing status via /sysfs/ file */ void mount_sysfs(ringbuffer *r, void (*f)(ringbuffer *r,char *fmt, ...)); @@ -31,11 +31,11 @@ fd sysfs_file_open(mount *m,char *path) return fd_from_sysfs(map[0],map[1]); } -int sysfs_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) +int sysfs_read_dir(mount *m,char *path, struct dirent *dirs, uint32_t *pos) { if(*pos>=count)return 0; - memcpy(dirs->name,names[*pos],strlen(names[*pos])+1); - dirs->inode=0; + memcpy(dirs->d_name,names[*pos],strlen(names[*pos])+1); + dirs->d_ino=0; *pos+=1; return 1; } |
