2012-08-22 12:32:13 +08:00
|
|
|
#ifndef __KERN_FS_FS_H__
|
|
|
|
#define __KERN_FS_FS_H__
|
|
|
|
|
|
|
|
#include <defs.h>
|
|
|
|
#include <mmu.h>
|
|
|
|
#include <sem.h>
|
|
|
|
#include <atomic.h>
|
|
|
|
|
|
|
|
#define SECTSIZE 512
|
|
|
|
#define PAGE_NSECT (PGSIZE / SECTSIZE)
|
|
|
|
|
|
|
|
#define SWAP_DEV_NO 1
|
|
|
|
#define DISK0_DEV_NO 2
|
|
|
|
#define DISK1_DEV_NO 3
|
|
|
|
|
|
|
|
void fs_init(void);
|
|
|
|
void fs_cleanup(void);
|
|
|
|
|
|
|
|
struct inode;
|
|
|
|
struct file;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* process's file related informaction
|
|
|
|
*/
|
|
|
|
struct files_struct {
|
|
|
|
struct inode *pwd; // inode of present working directory
|
|
|
|
struct file *fd_array; // opened files array
|
2012-09-14 21:36:57 +08:00
|
|
|
int files_count; // the number of opened files
|
2012-08-22 12:32:13 +08:00
|
|
|
semaphore_t files_sem; // lock protect sem
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FILES_STRUCT_BUFSIZE (PGSIZE - sizeof(struct files_struct))
|
|
|
|
#define FILES_STRUCT_NENTRY (FILES_STRUCT_BUFSIZE / sizeof(struct file))
|
|
|
|
|
|
|
|
void lock_files(struct files_struct *filesp);
|
|
|
|
void unlock_files(struct files_struct *filesp);
|
|
|
|
|
|
|
|
struct files_struct *files_create(void);
|
|
|
|
void files_destroy(struct files_struct *filesp);
|
|
|
|
void files_closeall(struct files_struct *filesp);
|
|
|
|
int dup_files(struct files_struct *to, struct files_struct *from);
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
files_count(struct files_struct *filesp) {
|
2012-09-14 21:36:57 +08:00
|
|
|
return filesp->files_count;
|
2012-08-22 12:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
files_count_inc(struct files_struct *filesp) {
|
2012-09-14 21:36:57 +08:00
|
|
|
filesp->files_count += 1;
|
|
|
|
return filesp->files_count;
|
2012-08-22 12:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
files_count_dec(struct files_struct *filesp) {
|
2012-09-14 21:36:57 +08:00
|
|
|
filesp->files_count -= 1;
|
|
|
|
return filesp->files_count;
|
2012-08-22 12:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !__KERN_FS_FS_H__ */
|
|
|
|
|