update codes

This commit is contained in:
chyyuu
2012-09-14 21:36:57 +08:00
parent c417874aa8
commit 92c553113b
32 changed files with 506 additions and 1809 deletions

View File

@@ -27,7 +27,7 @@ fd_array_init(struct file *fd_array) {
int fd;
struct file *file = fd_array;
for (fd = 0; fd < FILES_STRUCT_NENTRY; fd ++, file ++) {
atomic_set(&(file->open_count), 0);
file->open_count = 0;
file->status = FD_NONE, file->fd = fd;
}
}

View File

@@ -20,7 +20,7 @@ struct file {
int fd;
off_t pos;
struct inode *node;
atomic_t open_count;
int open_count;
};
void fd_array_init(struct file *fd_array);
@@ -43,17 +43,19 @@ int file_mkfifo(const char *name, uint32_t open_flags);
static inline int
fopen_count(struct file *file) {
return atomic_read(&(file->open_count));
return file->open_count;
}
static inline int
fopen_count_inc(struct file *file) {
return atomic_add_return(&(file->open_count), 1);
file->open_count += 1;
return file->open_count;
}
static inline int
fopen_count_dec(struct file *file) {
return atomic_sub_return(&(file->open_count), 1);
file->open_count -= 1;
return file->open_count;
}
#endif /* !__KERN_FS_FILE_H__ */

View File

@@ -38,7 +38,7 @@ files_create(void) {
if ((filesp = kmalloc(sizeof(struct files_struct) + FILES_STRUCT_BUFSIZE)) != NULL) {
filesp->pwd = NULL;
filesp->fd_array = (void *)(filesp + 1);
atomic_set(&(filesp->files_count), 0);
filesp->files_count = 0;
sem_init(&(filesp->files_sem), 1);
fd_array_init(filesp->fd_array);
}

View File

@@ -25,7 +25,7 @@ struct file;
struct files_struct {
struct inode *pwd; // inode of present working directory
struct file *fd_array; // opened files array
atomic_t files_count; // the number of opened files
int files_count; // the number of opened files
semaphore_t files_sem; // lock protect sem
};
@@ -42,17 +42,19 @@ int dup_files(struct files_struct *to, struct files_struct *from);
static inline int
files_count(struct files_struct *filesp) {
return atomic_read(&(filesp->files_count));
return filesp->files_count;
}
static inline int
files_count_inc(struct files_struct *filesp) {
return atomic_add_return(&(filesp->files_count), 1);
filesp->files_count += 1;
return filesp->files_count;
}
static inline int
files_count_dec(struct files_struct *filesp) {
return atomic_sub_return(&(filesp->files_count), 1);
filesp->files_count -= 1;
return filesp->files_count;
}
#endif /* !__KERN_FS_FS_H__ */

View File

@@ -26,8 +26,8 @@ __alloc_inode(int type) {
* */
void
inode_init(struct inode *node, const struct inode_ops *ops, struct fs *fs) {
atomic_set(&(node->ref_count), 0);
atomic_set(&(node->open_count), 0);
node->ref_count = 0;
node->open_count = 0;
node->in_ops = ops, node->in_fs = fs;
vop_ref_inc(node);
}
@@ -49,7 +49,8 @@ inode_kill(struct inode *node) {
* */
int
inode_ref_inc(struct inode *node) {
return atomic_add_return(&(node->ref_count), 1);
node->ref_count += 1;
return node->ref_count;
}
/* *
@@ -61,7 +62,9 @@ int
inode_ref_dec(struct inode *node) {
assert(inode_ref_count(node) > 0);
int ref_count, ret;
if ((ref_count = atomic_sub_return(&(node->ref_count), 1)) == 0) {
node->ref_count-= 1;
ref_count = node->ref_count;
if (ref_count == 0) {
if ((ret = vop_reclaim(node)) != 0 && ret != -E_BUSY) {
cprintf("vfs: warning: vop_reclaim: %e.\n", ret);
}
@@ -75,7 +78,8 @@ inode_ref_dec(struct inode *node) {
* */
int
inode_open_inc(struct inode *node) {
return atomic_add_return(&(node->open_count), 1);
node->open_count += 1;
return node->open_count;
}
/* *
@@ -87,7 +91,9 @@ int
inode_open_dec(struct inode *node) {
assert(inode_open_count(node) > 0);
int open_count, ret;
if ((open_count = atomic_sub_return(&(node->open_count), 1)) == 0) {
node->open_count -= 1;
open_count = node->open_count;
if (open_count == 0) {
if ((ret = vop_close(node)) != 0) {
cprintf("vfs: warning: vop_close: %e.\n", ret);
}

View File

@@ -35,8 +35,8 @@ struct inode {
inode_type_device_info = 0x1234,
inode_type_sfs_inode_info,
} in_type;
atomic_t ref_count;
atomic_t open_count;
int ref_count;
int open_count;
struct fs *in_fs;
const struct inode_ops *in_ops;
};
@@ -236,12 +236,12 @@ void inode_check(struct inode *node, const char *opstr);
static inline int
inode_ref_count(struct inode *node) {
return atomic_read(&(node->ref_count));
return node->ref_count;
}
static inline int
inode_open_count(struct inode *node) {
return atomic_read(&(node->open_count));
return node->open_count;
}
#endif /* !__KERN_FS_VFS_INODE_H__ */