Main Page | Directories | File List | Globals

file.c

Go to the documentation of this file.
00001 /*
00002  * kernel_sys/file.c
00003  *
00004  * Copyright (c) 2003-2005 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2005/04
00008  * Author:      Lukasz Dembinski
00009  * Info:        It's only stub for real virtual filesystem
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/fs.h>
00016 #include <agnix/terminal.h>
00017 #include <agnix/memory.h>
00018 #include <agnix/console.h>
00019 
00020 #define MOD_NAME        "VFS: "
00021 
00022 int file_install_fd(struct file_s *file)
00023 {
00024     int fd;
00025     
00026     if ((fd = get_free_resource(current_task->files->fd_resource_desc)) < 0)
00027         return -1;
00028 
00029     if (fd > MAX_FILES)
00030         return -1;
00031 
00032     current_task->files->file[fd] = file;
00033     
00034     return fd;
00035 }
00036 
00037 struct file_s *file_create(void)
00038 {
00039     struct file_s *file;
00040     
00041     file = (struct file_s *)get_free_pages(0);
00042     
00043     return file;
00044 }
00045 
00046 void file_destroy(struct file_s *file)
00047 {
00048     put_free_pages((u32)file, 0);
00049 }
00050 
00051 struct file_s **file_table_create(void)
00052 {
00053     struct file_s **file;
00054     
00055     file = (struct file_s **)get_free_pages(0);
00056     
00057     return file;
00058 }
00059 
00060 struct files_s *files_create(void)
00061 {
00062     struct files_s *files;
00063 
00064     files = (struct files_s *)get_free_pages(0);
00065 
00066     files->fd_resource.resource_name   = "fds";
00067     files->fd_resource.resource_bitmap = files->fd;
00068     files->fd_resource.resource_len    = FILES_BITMAP_LEN;
00069     files->file                        = file_table_create();
00070     
00071     files->fd_resource_desc = register_resource(&files->fd_resource);
00072 
00073     return files;
00074 }
00075 
00076 struct files_s *files_copy(struct files_s *cur_files)
00077 {
00078     struct files_s *files;
00079     
00080     files = files_create();
00081     
00082     memcpy(files->fd, cur_files->fd, FILES_BITMAP_LEN);
00083 
00084     return files;
00085 }
00086 
00087 int files_fork(struct task_s *cur_task, struct task_s *new_task)
00088 {
00089     if (cur_task->files == NULL) {
00090         new_task->files = files_create();
00091     } else {
00092         new_task->files = files_copy(cur_task->files);
00093     }
00094     
00095     return 0;
00096 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix