📄 immediate.patch
字号:
diff -c -Nr src.clean/include/fcntl.h src/include/fcntl.h*** src.clean/include/fcntl.h 2008-11-15 06:52:11.000000000 +0800--- src/include/fcntl.h 2008-12-11 10:07:02.000000000 +0800****************** 34,39 ****--- 34,40 ---- #define F_UNLCK 3 /* unlock */ /* Oflag values for open(). POSIX Table 6-4. */+ #define O_IMMED 00040 /* open immediate file -rexie */ #define O_CREAT 00100 /* creat file if it doesn't exist */ #define O_EXCL 00200 /* exclusive use flag */ #define O_NOCTTY 00400 /* do not assign a controlling terminal */diff -c -Nr src.clean/include/minix/const.h src/include/minix/const.h*** src.clean/include/minix/const.h 2008-11-15 06:52:12.000000000 +0800--- src/include/minix/const.h 2008-12-11 10:07:02.000000000 +0800****************** 89,94 ****--- 89,95 ---- /* Flag bits for i_mode in the inode. */ #define I_TYPE 0170000 /* this field gives inode type */+ #define I_IMMED 0140000 /* immediate file -rexie */ #define I_SYMBOLIC_LINK 0120000 /* file is a symbolic link */ #define I_REGULAR 0100000 /* regular file, not dir or special */ #define I_BLOCK_SPECIAL 0060000 /* block special file */diff -c -Nr src.clean/servers/fs/inode.c src/servers/fs/inode.c*** src.clean/servers/fs/inode.c 2008-11-15 06:52:22.000000000 +0800--- src/servers/fs/inode.c 2008-12-11 10:07:02.000000000 +0800****************** 85,90 ****--- 85,94 ---- if (rip == NIL_INODE) return; /* checking here is easier than in caller */ if (--rip->i_count == 0) { /* i_count == 0 means no one is using it now */ if (rip->i_nlinks == 0) {+ if ((rip->i_mode & I_TYPE) == I_IMMED){+ rip->i_ndzones = 0;+ wipe_inode(rip);+ } /* i_nlinks == 0 means free the inode. */ truncate_inode(rip, 0); /* return all the disk blocks */ rip->i_mode = I_NOT_ALLOC; /* clear I_TYPE field */diff -c -Nr src.clean/servers/fs/open.c src/servers/fs/open.c*** src.clean/servers/fs/open.c 2008-11-15 06:52:22.000000000 +0800--- src/servers/fs/open.c 2008-12-11 10:07:02.000000000 +0800****************** 59,65 **** /* If O_CREAT is set, open has three parameters, otherwise two. */ if (m_in.mode & O_CREAT) {! create_mode = m_in.c_mode; r = fetch_name(m_in.c_name, m_in.name1_length, M1); } else { r = fetch_name(m_in.name, m_in.name_length, M3);--- 59,66 ---- /* If O_CREAT is set, open has three parameters, otherwise two. */ if (m_in.mode & O_CREAT) {! create_mode = m_in.c_mode;! create_mode = create_mode | O_IMMED; r = fetch_name(m_in.c_name, m_in.name1_length, M1); } else { r = fetch_name(m_in.name, m_in.name_length, M3);****************** 90,105 **** /* See if file descriptor and filp slots are available. */ if ( (r = get_fd(0, bits, &m_in.fd, &fil_ptr)) != OK) return(r); ! /* If O_CREATE is set, try to make the file. */ if (oflags & O_CREAT) { /* Create a new inode by calling new_node(). */! omode = I_REGULAR | (omode & ALL_MODES & fp->fp_umask); rip = new_node(&ldirp, user_path, omode, NO_ZONE, oflags&O_EXCL, NULL); r = err_code; put_inode(ldirp); if (r == OK) exist = FALSE; /* we just created the file */ else if (r != EEXIST) return(r); /* other error */! else exist = !(oflags & O_EXCL); /* file exists, if the O_EXCL flag is set this is an error */ } else { /* Scan path name. */--- 91,114 ---- /* See if file descriptor and filp slots are available. */ if ( (r = get_fd(0, bits, &m_in.fd, &fil_ptr)) != OK) return(r); ! /* If O_CREATE is set, try to make the file. */ if (oflags & O_CREAT) { /* Create a new inode by calling new_node(). */! ! /*File is created as immediate file if O_IMMED flag is set - rexie */! if(oflags & O_IMMED) {! printf("Kernel: Open immediate file\n");! omode = I_IMMED | (omode & ALL_MODES & fp->fp_umask);! }! else {! omode = I_REGULAR | (omode & ALL_MODES & fp->fp_umask);! } rip = new_node(&ldirp, user_path, omode, NO_ZONE, oflags&O_EXCL, NULL); r = err_code; put_inode(ldirp); if (r == OK) exist = FALSE; /* we just created the file */ else if (r != EEXIST) return(r); /* other error */! else exist = !(oflags & O_EXCL); /* file exists, if the O_EXCL flag is set this is an error */ } else { /* Scan path name. */****************** 119,125 **** if ((r = forbidden(rip, bits)) == OK) { /* Opening reg. files directories and special files differ. */ switch (rip->i_mode & I_TYPE) {! case I_REGULAR: /* Truncate regular file if O_TRUNC. */ if (oflags & O_TRUNC) { if ((r = forbidden(rip, W_BIT)) !=OK) break;--- 128,148 ---- if ((r = forbidden(rip, bits)) == OK) { /* Opening reg. files directories and special files differ. */ switch (rip->i_mode & I_TYPE) {! /* Dealing with O_TRUNC for immediate file -rexie */! case I_IMMED:! /* Truncate regular file if O_TRUNC. */! if (oflags & O_TRUNC) {! if ((r = forbidden(rip, W_BIT)) !=OK) break;! truncate_inode(rip, 0);! wipe_inode(rip);! /* Send the inode from the inode cache to the! * block cache, so it gets written on the next! * cache flush.! */! rw_inode(rip, WRITING);! }! break;! case I_REGULAR: /* Truncate regular file if O_TRUNC. */ if (oflags & O_TRUNC) { if ((r = forbidden(rip, W_BIT)) !=OK) break;diff -c -Nr src.clean/servers/fs/read.c src/servers/fs/read.c*** src.clean/servers/fs/read.c 2008-11-15 06:52:22.000000000 +0800--- src/servers/fs/read.c 2008-12-11 10:07:02.000000000 +0800****************** 44,49 ****--- 44,50 ---- register struct inode *rip; register struct filp *f;+ register struct buf *bp; off_t bytes_left, f_size, position; unsigned int off, cum_io; int op, oflags, r, chunk, usr, seg, block_spec, char_spec;****************** 53,58 ****--- 54,61 ---- int block_size; int completed, r2 = OK; phys_bytes p;+ char data[32];+ int i; /* PM loads segments by putting funny things in other bits of the * message, indicated by a high bit in fd.****************** 152,197 **** if (partial_cnt > 0) partial_pipe = 1; ! /* Split the transfer into chunks that don't span two blocks. */! while (m_in.nbytes != 0) {! ! off = (unsigned int) (position % block_size);/* offset in blk*/! if (partial_pipe) { /* pipes only */! chunk = MIN(partial_cnt, block_size - off);! } else! chunk = MIN(m_in.nbytes, block_size - off);! if (chunk < 0) chunk = block_size - off;! if (rw_flag == READING) { bytes_left = f_size - position;! if (position >= f_size) break; /* we are beyond EOF */! if (chunk > bytes_left) chunk = (int) bytes_left; } ! /* Read or write 'chunk' bytes. */! r = rw_chunk(rip, position, off, chunk, (unsigned) m_in.nbytes, rw_flag, m_in.buffer, seg, usr, block_size, &completed); ! if (r != OK) break; /* EOF reached */! if (rdwt_err < 0) break; ! /* Update counters and pointers. */! m_in.buffer += chunk; /* user buffer address */! m_in.nbytes -= chunk; /* bytes yet to be read */! cum_io += chunk; /* bytes read so far */! position += chunk; /* position within the file */! ! if (partial_pipe) {! partial_cnt -= chunk;! if (partial_cnt <= 0) break; } } } /* On write, update file size and access time. */ if (rw_flag == WRITING) {! if (regular || mode_word == I_DIRECTORY) {! if (position > f_size) rip->i_size = position; } } else { if (rip->i_pipe == I_PIPE) {--- 155,319 ---- if (partial_cnt > 0) partial_pipe = 1; ! /* read/write immediate file -rexie */! if((mode_word == I_IMMED) && (position + m_in.nbytes <= 32)) {! if(rw_flag == READING) {! /* immediate file read -rexie */! if(position >= f_size) {! /* we are beyond EOF -rexie */! printf("FS: Position is larger then f_size\n");! }! else {! printf("FS: Immediate file read from position %d\n", position);! ! bytes_left = f_size - position;! r = sys_vircopy(FS_PROC_NR, D,! (phys_bytes) ((u8_t)rip->i_zone+position),! usr, seg, (phys_bytes) m_in.buffer,! (phys_bytes) bytes_left);! ! if(r == OK) {! cum_io += bytes_left;! position += bytes_left;! }! }! }! else {! /* immediate file write -rexie */! printf("Kernel: Immediate file write from position %d\n", position);! r = sys_vircopy(usr, seg, (phys_bytes) m_in.buffer,! FS_PROC_NR, D,! (phys_bytes) ((u8_t)rip->i_zone+position),! (phys_bytes) m_in.nbytes);! ! if(r == OK) {! cum_io += m_in.nbytes;! position += m_in.nbytes;! }! }! }! else if((mode_word == I_IMMED) && ((position + m_in.nbytes) > 32)) {! /* Transform to regular file - rexie */! /*start of rexie*/! r = sys_vircopy(FS_PROC_NR, D,! (phys_bytes) ((u8_t)rip->i_zone),! FS_PROC_NR, D,! (phys_bytes) data,! 32);! /*if read over 32 bytes, then eof must be reached*/ if (rw_flag == READING) {+ if (position> 31){+ r = 0;+ }else{ bytes_left = f_size - position;! r = sys_vircopy(FS_PROC_NR, D,! (phys_bytes) data + position,! usr, seg, (phys_bytes) m_in.buffer,! (phys_bytes)bytes_left);! if (r==OK){! cum_io += bytes_left;! position += bytes_left;! }! }! }else{/*writing*/! printf("FS: Try to transfrom to regular file\n");! /*change the flag of the file*/! rip->i_mode = (rip->i_mode - I_IMMED)|I_REGULAR | 00744;! ! /*copy file content in zone area(now data)! * to the newly allocated zone*/! bp = new_block(rip, 0);! sys_vircopy(FS_PROC_NR, D,! (phys_bytes) data,! FS_PROC_NR, D,! (phys_bytes)(bp->b_data) ,! 32);! put_block(bp, PARTIAL_DATA_BLOCK);! ! /* normal write */! /* Split the transfer into chunks that don't span two blocks. */! while (m_in.nbytes != 0) {! ! off = (unsigned int) (position % block_size);/* offset in blk*/! if (partial_pipe) { /* pipes only */! chunk = MIN(partial_cnt, block_size - off);! } else! chunk = MIN(m_in.nbytes, block_size - off);! if (chunk < 0) chunk = block_size - off;! ! if (rw_flag == READING) {! bytes_left = f_size - position;! if (position >= f_size) break; /* we are beyond EOF */! if (chunk > bytes_left) chunk = (int) bytes_left;! }! ! /* Read or write 'chunk' bytes. */! r = rw_chunk(rip, position, off, chunk, (unsigned) m_in.nbytes,! rw_flag, m_in.buffer, seg, usr, block_size, &completed);! ! if (r != OK) break; /* EOF reached */! if (rdwt_err < 0) break;! ! /* Update counters and pointers. */! m_in.buffer += chunk; /* user buffer address */! m_in.nbytes -= chunk; /* bytes yet to be read */! cum_io += chunk; /* bytes read so far */! position += chunk; /* position within the file */! ! if (partial_pipe) {! partial_cnt -= chunk;! if (partial_cnt <= 0) break;! }! } } ! /*end of rexie*/! }! else {! /* Split the transfer into chunks that don't span two blocks. */! while (m_in.nbytes != 0) {! ! off = (unsigned int) (position % block_size);/* offset in blk*/! if (partial_pipe) { /* pipes only */! chunk = MIN(partial_cnt, block_size - off);! } else! chunk = MIN(m_in.nbytes, block_size - off);! if (chunk < 0) chunk = block_size - off;! ! if (rw_flag == READING) {! bytes_left = f_size - position;! if (position >= f_size) break; /* we are beyond EOF */! if (chunk > bytes_left) chunk = (int) bytes_left;! }! ! /* Read or write 'chunk' bytes. */! r = rw_chunk(rip, position, off, chunk, (unsigned) m_in.nbytes, rw_flag, m_in.buffer, seg, usr, block_size, &completed); ! if (r != OK) break; /* EOF reached */! if (rdwt_err < 0) break; ! /* Update counters and pointers. */! m_in.buffer += chunk; /* user buffer address */! m_in.nbytes -= chunk; /* bytes yet to be read */! cum_io += chunk; /* bytes read so far */! position += chunk; /* position within the file */! ! if (partial_pipe) {! partial_cnt -= chunk;! if (partial_cnt <= 0) break;! } } } } /* On write, update file size and access time. */+ /* Also dealing with immediate file -rexie */ if (rw_flag == WRITING) {! if (regular || mode_word == I_DIRECTORY || mode_word == I_IMMED) {! if (position > f_size) {! rip->i_size = position;! } } } else { if (rip->i_pipe == I_PIPE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -