From 02c56248246fed7a9a923a108ddfc7b7b7f552ca Mon Sep 17 00:00:00 2001 From: xiaoyi1212 Date: Mon, 27 May 2024 22:33:06 +0800 Subject: [PATCH] =?UTF-8?q?ISO=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-CN.md | 1 + README.md | 1 + src/fs/iso9660.c | 200 +++++++++++++++++++++++++----------------- src/include/iso9660.h | 14 ++- 4 files changed, 132 insertions(+), 84 deletions(-) diff --git a/README-zh-CN.md b/README-zh-CN.md index 387a3e8..dbde1b6 100644 --- a/README-zh-CN.md +++ b/README-zh-CN.md @@ -39,4 +39,5 @@ ### 贡献者们 * XIAOYI12 - xiaoyi1212 负责主要的OS开发 +* min0911Y - min0911 负责OS文件系统开发 * QtLittleXu - XuYuxuan 负责OS文档编写 diff --git a/README.md b/README.md index c078e83..c6b7f89 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,5 @@ Welcome to create pull requests or issues to this project. I am really happy to ### Contributors * XIAOYI12 - xiaoyi12 OS Development +* min0911Y - min0911 OS FileSystem Development * QtLittleXu - XuYuxuan OS Document \ No newline at end of file diff --git a/src/fs/iso9660.c b/src/fs/iso9660.c index 360b511..9e11f49 100644 --- a/src/fs/iso9660.c +++ b/src/fs/iso9660.c @@ -38,8 +38,8 @@ static l9660_file *last_file; static char gbuf[2048]; #endif -l9660_fs *fs; -l9660_dir *root_dir; + +#define get_now_dir(vfs) ((l9660_fs_status_t *)(vfs->cache))->now_dir static char *strchrnul(const char *s, int c) { @@ -341,8 +341,7 @@ bool ISO_Check(uint8_t disk_number) kfree(buffer); return true; // 是 ISO9660 文件系统 } - else - { + else{ kfree(buffer); return false; // 不是 ISO9660 文件系统 } @@ -350,12 +349,16 @@ bool ISO_Check(uint8_t disk_number) void ISO_InitFs(struct vfs_t *vfs, uint8_t disk_number) { - fs = (l9660_fs *)kmalloc(sizeof(l9660_fs)); - vfs->cache = (void *)fs; + l9660_fs_status_t *fs_m; + fs_m = (l9660_fs_status_t*) kmalloc(sizeof(l9660_fs_status_t)); + + fs_m->fs = (l9660_fs *)kmalloc(sizeof(l9660_fs)); + vfs->cache = (void *)fs_m; printf("ISO Load init..."); - l9660_status a = l9660_openfs(fs,read_sector,disk_number); - a = l9660_fs_open_root(root_dir, fs); - printf("%d\n",a); + l9660_openfs(fs_m->fs,read_sector,disk_number); + l9660_fs_open_root(&fs_m->root_dir, fs_m->fs); + fs_m->now_dir = fs_m->root_dir; + logkf("%08x\n",vfs->cache); /* l9660_file file; for (;;) { @@ -390,89 +393,125 @@ void ISO_InitFs(struct vfs_t *vfs, uint8_t disk_number) void ISO_CDFile(){} vfs_file *ISO_GetFile(char* path1){ - l9660_dir bmpDict; - char *path = (char *)kmalloc(strlen(path1) + 1); - char *bmp = path; - strcpy(path, path1); - strtoupper(path); - if (strncmp("/", path, 1) == 0) { - path += 1; - bmpDict = root_dir; - } - if (path[0] == '\\' || path[0] == '/') { - // 跳过反斜杠和正斜杠 - for (int i = 0; i < strlen(path); i++) { - if (path[i] != '\\' && path[i] != '/') { - path += i; - break; - } - } - } - char *temp_name = (char *)kmalloc(128); - int i = 0; - l9660_file *finfo; - while (1) { - int j; - for (j = 0; i < strlen(path); i++, j++) { - if (path[i] == '\\' || path[i] == '/') { - temp_name[j] = '\0'; - i++; - break; - } - temp_name[j] = path[i]; - } - finfo = dict_search(temp_name, bmpDict, get_directory_max(bmpDict, vfs)); - - if (finfo == 0) { - if (path[i] != 0) { - bmpDict = NULL; - } - goto END; - } else { - if (get_clustno(finfo->clustno_high, finfo->clustno_low) != 0) { - for (int count = 1; - FindForCount(count, get_dm(vfs).directory_clustno_list) != NULL; - count++) { - struct List *list = - FindForCount(count, get_dm(vfs).directory_clustno_list); - if (get_clustno(finfo->clustno_high, finfo->clustno_low) == - list->val) { - list = FindForCount(count, get_dm(vfs).directory_list); - bmpDict = (struct FAT_FILEINFO *)list->val; - break; - } - } - } else { - bmpDict = root_dir; - } - memclean(temp_name, 128); - if (path[i] == '\0') { - goto END; - } - } - } - END: - kfree((void *)temp_name); - kfree(((void *)bmp)); - return bmpDict; +// strtoupper(path1); +// if (strcmp(path1, "/") == 0) { +// return fs_m->root_dir; +// } + return NULL; } void ISO_CopyCache(struct vfs_t *dest, struct vfs_t *src){ - dest->cache = kmalloc(sizeof(l9660_fs)); - memcpy(dest->cache, src->cache, sizeof(l9660_fs)); + dest->cache = kmalloc(sizeof(l9660_fs_status_t)); + memcpy(dest->cache, src->cache, sizeof(l9660_fs_status_t)); } -void ISO_cd(struct vfs_t *vfs, char *dictName){ +int ISO_cd(struct vfs_t *vfs, char *dictname){ +// +// strtoupper(dictname); +// + if (strcmp(dictname, "/") == 0) { + while (vfs->path->ctl->all != 0) { + kfree((FindForCount(vfs->path->ctl->all, vfs->path)->val)); + DeleteVal(vfs->path->ctl->all, vfs->path); + } + l9660_fs_status_t *fs_m = (l9660_fs_status_t *)vfs->cache; + get_now_dir(vfs) = fs_m->root_dir; + return 1; + } + l9660_dir finfo; + l9660_status a = l9660_opendirat(&finfo,&get_now_dir(vfs),dictname); + if (a) { + return 0; + } + get_now_dir(vfs) = finfo; + if (strcmp(dictname, "..") != 0 && strcmp(dictname, ".") != 0) { + char *dict = kmalloc(255); + strcpy(dict, dictname); + AddVal(dict, vfs->path); + } + + if (strcmp(dictname, "..") == 0) { + kfree((FindForCount(vfs->path->ctl->all, vfs->path)->val)); + DeleteVal(vfs->path->ctl->all, vfs->path); + } + return 1; } -void ISO_ReadFile(struct vfs_t *vfs, char *path, char *buffer){ - +bool ISO_ReadFile(struct vfs_t *vfs, char *path, char *buffer){ + l9660_file file; + l9660_status a = l9660_openat(&file, &get_now_dir(vfs),path); + if(a) { + return false; // not found + } + for(;;) { + size_t read; + l9660_read(&file, buffer, 128, &read); + if (read == 0) + break; + buffer += read; + } + return true; } -void ISO_ListFile(struct vfs_t *vfs, char *dictpath){ +List *ISO_ListFile(struct vfs_t *vfs, char *dictpath){ + l9660_dir finfo; + if(strcmp(dictpath,"") == 0) + finfo = get_now_dir(vfs); + else { + l9660_status a = l9660_opendirat(&finfo,&get_now_dir(vfs),dictpath); + if (a) { + return NULL; + } + } + + List *result = NewList(); + for (;;) { + l9660_dirent *dent; + l9660_readdir(&finfo, &dent); + + if (dent == 0) + break; + vfs_file *d = kmalloc(sizeof(vfs_file)); + memclean((void *)d,sizeof(vfs_file)); + int j = 0; + if(memcmp("\0",dent->name,dent->name_len) == 0) { + d->name[j++] = '.'; + d->name[j] = 0; + } else if (memcmp("\1",dent->name,dent->name_len) == 0) { + d->name[j++] = '.'; + d->name[j++] = '.'; + d->name[j] = 0; + } + else + for(;jname_len;j++) { + if(dent->name[j] == ';') { + break; + } + + d->name[j] = dent->name[j]; + } + d->name[j] = 0; + d->type = FLE; + if(dent->flags & DENT_ISDIR) { + d->type = DIR; + } else { + d->size = READ32(dent->size); + } + AddVal(d, result); + } + return result; } +int ISO_FileSize(struct vfs_t *vfs, char *filename) { + l9660_file file; + l9660_status a = l9660_openat(&file, &get_now_dir(vfs),filename); + if(a) { + return -1; // not found + } + return file.length; +} + void init_iso9660() { @@ -491,6 +530,7 @@ void init_iso9660() fs.cd = ISO_cd; fs.ReadFile = ISO_ReadFile; fs.ListFile = ISO_ListFile; + fs.FileSize = ISO_FileSize; vfs_register_fs(fs); } diff --git a/src/include/iso9660.h b/src/include/iso9660.h index de02b9f..02de71d 100644 --- a/src/include/iso9660.h +++ b/src/include/iso9660.h @@ -8,6 +8,7 @@ #include #include #include "common.h" +#include "list.h" typedef enum { /*! Success! */ @@ -121,10 +122,8 @@ typedef union { char _bits[2048]; } l9660_vdesc; -/* File system structure. - * Stick this inside your own structure and cast/offset as appropriate to store - * private data - */ +typedef struct l9660_file ; + typedef struct l9660_fs { #ifdef L9660_SINGLEBUFFER union { @@ -157,6 +156,13 @@ typedef struct { l9660_file file; } l9660_dir; +typedef struct l9660_fs_status{ + l9660_fs *fs; + l9660_dir root_dir; + l9660_dir now_dir; + +}l9660_fs_status_t; + uint32_t l9660_tell(l9660_file *f); l9660_status l9660_read(l9660_file *f, void *buf, size_t size, size_t *read); l9660_status l9660_seek(l9660_file *f, int whence, int32_t offset);