Newer
Older
#include "param.h"
#include "x86.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
#include "fs.h"
#include "fsvar.h"
for(i = 0; i < NFILE; i++){
if(file[i].type == FD_CLOSED){
file[i].type = FD_NONE;
file[i].ref = 1;
// Increment ref count for file f.
void
fileincref(struct file *f)
acquire(&file_table_lock);
if(f->ref < 1 || f->type == FD_CLOSED)
panic("fileincref");
f->ref++;
release(&file_table_lock);
if(f->type == FD_INODE){
ip = ilock(f->ip);
if((r = readi(ip, addr, f->off, n)) > 0)
// Write to file f. Addr is kernel address.
int
filewrite(struct file *f, char *addr, int n)
if(f->writable == 0)
return -1;
if(f->type == FD_PIPE)
return pipe_write(f->pipe, addr, n);
if(f->type == FD_INODE){
ip = ilock(f->ip);
if((r = writei(ip, addr, f->off, n)) > 0)
struct inode *ip;
if(f->type == FD_INODE){
ip = ilock(f->ip);
stati(ip, st);
iunlock(ip);
panic("fileclose");
if(--f->ref > 0){
release(&file_table_lock);
return;
}
ff = *f;
f->ref = 0;
f->type = FD_CLOSED;
if(ff.type == FD_PIPE)
pipe_close(ff.pipe, ff.writable);