#ifndef __MFS_BUF_H__
#define __MFS_BUF_H__
+#include "clean.h"
+
/* Buffer (block) cache. To acquire a block, a routine calls get_block(),
* telling which block it wants. The block is then regarded as "in use"
* and has its 'b_count' field incremented. All the blocks that are not
* Avoid hysteresis by flushing all other dirty blocks for the same device.
*/
if (bp->b_dev != NO_DEV) {
- if (bp->b_dirt == DIRTY) flushall(bp->b_dev);
+ if (ISDIRTY(bp)) flushall(bp->b_dev);
/* Are we throwing out a block that contained something?
* Give it to VM for the second-layer cache.
}
}
- bp->b_dirt = CLEAN;
-
+ MARKCLEAN(bp);
}
/*===========================================================================*
}
for (bp = &buf[0], ndirty = 0; bp < &buf[nr_bufs]; bp++)
- if (bp->b_dirt == DIRTY && bp->b_dev == dev) dirty[ndirty++] = bp;
+ if (ISDIRTY(bp) && bp->b_dev == dev) dirty[ndirty++] = bp;
rw_scattered(dev, dirty, ndirty, WRITING);
}
bp->b_dev = dev; /* validate block */
put_block(bp, PARTIAL_DATA_BLOCK);
} else {
- bp->b_dirt = CLEAN;
+ MARKCLEAN(bp);
}
r -= fs_block_size;
}
--- /dev/null
+
+#ifndef _MFS_CLEAN_H
+#define _MFS_CLEAN_H 1
+
+#define MARKDIRTY(b) ((b)->b_dirt = BP_DIRTY)
+#define MARKCLEAN(b) ((b)->b_dirt = BP_CLEAN)
+
+#define ISDIRTY(b) ((b)->b_dirt == BP_DIRTY)
+#define ISCLEAN(b) ((b)->b_dirt == BP_CLEAN)
+
+#endif
#define IGN_PERM 0
#define CHK_PERM 1
-#define CLEAN 0 /* disk and memory copies identical */
-#define DIRTY 1 /* disk and memory copies differ */
+#define BP_CLEAN 0 /* on-disk block and memory copies identical */
+#define BP_DIRTY 1 /* on-disk block and memory copies differ */
+#define IN_CLEAN 0 /* in-block inode and memory copies identical */
+#define IN_DIRTY 1 /* in-block inode and memory copies differ */
#define ATIME 002 /* set if atime field needs updating */
#define CTIME 004 /* set if ctime field needs updating */
#define MTIME 010 /* set if mtime field needs updating */
*/
(void) truncate_inode(rip, (off_t) 0);
rip->i_mode = I_NOT_ALLOC; /* clear I_TYPE field */
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
free_inode(rip->i_dev, rip->i_num);
}
rip->i_mountpoint = FALSE;
- if (rip->i_dirt == DIRTY) rw_inode(rip, WRITING);
+ if (IN_ISDIRTY(rip)) rw_inode(rip, WRITING);
if (rip->i_nlinks == NO_LINK) {
/* free, put at the front of the LRU list */
rip->i_size = 0;
rip->i_update = ATIME | CTIME | MTIME; /* update all times later */
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
for (i = 0; i < V2_NR_TZONES; i++) rip->i_zone[i] = NO_ZONE;
}
/* Do the read or write. */
if (rw_flag == WRITING) {
if (rip->i_update) update_times(rip); /* times need updating */
- if (sp->s_rd_only == FALSE) bp->b_dirt = DIRTY;
+ if (sp->s_rd_only == FALSE) MARKDIRTY(bp);
}
/* Copy the inode from the disk block to the in-core table or vice versa.
new_icopy(rip, dip2, rw_flag, sp->s_native);
put_block(bp, INODE_BLOCK);
- rip->i_dirt = CLEAN;
+ IN_MARKCLEAN(rip);
}
#define NO_SEEK 0 /* i_seek = NO_SEEK if last op was not SEEK */
#define ISEEK 1 /* i_seek = ISEEK if last op was SEEK */
+#define IN_MARKCLEAN(i) i->i_dirt = IN_CLEAN
+#define IN_MARKDIRTY(i) i->i_dirt = IN_DIRTY
+
+#define IN_ISCLEAN(i) i->i_dirt == IN_CLEAN
+#define IN_ISDIRTY(i) i->i_dirt == IN_DIRTY
+
#endif
if(r == OK) {
rip->i_nlinks++;
rip->i_update |= CTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
}
/* Done. Release both inodes. */
if (r == OK) {
rip->i_nlinks--; /* entry deleted from parent's dir */
rip->i_update |= CTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
}
put_inode(rip);
if(search_dir(old_ip, dot2, &numb, ENTER, IGN_PERM) == OK) {
/* New link created. */
new_dirp->i_nlinks++;
- new_dirp->i_dirt = DIRTY;
+ IN_MARKDIRTY(new_dirp);
}
}
/* Next correct the inode size. */
rip->i_size = newsize;
rip->i_update |= CTIME | MTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
return(OK);
}
}
rip->i_update |= CTIME | MTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
return(OK);
}
if (bytes > (size_t) len)
bytes = len;
memset(bp->b_data + offset, 0, bytes);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
put_block(bp, FULL_DATA_BLOCK);
pos += bytes;
#include <minix/vfsif.h>
#include <minix/bdev.h>
#include "inode.h"
-
+#include "clean.h"
/*===========================================================================*
* fs_sync *
/* Write all the dirty inodes to the disk. */
for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
- if(rip->i_count > 0 && rip->i_dirt == DIRTY) rw_inode(rip, WRITING);
+ if(rip->i_count > 0 && IN_ISDIRTY(rip)) rw_inode(rip, WRITING);
/* Write all the dirty blocks to the disk, one drive at a time. */
for(bp = &buf[0]; bp < &buf[nr_bufs]; bp++)
- if(bp->b_dev != NO_DEV && bp->b_dirt == DIRTY)
+ if(bp->b_dev != NO_DEV && ISDIRTY(bp))
flushall(bp->b_dev);
return(OK); /* sync() can't fail */
/* Normal case. It was possible to enter . and .. in the new dir. */
rip->i_nlinks++; /* this accounts for . */
ldirp->i_nlinks++; /* this accounts for .. */
- ldirp->i_dirt = DIRTY; /* mark parent's inode as dirty */
+ IN_MARKDIRTY(ldirp); /* mark parent's inode as dirty */
} else {
/* It was not possible to enter . or .. probably disk was full -
* links counts haven't been touched. */
panic("Dir disappeared: %ul", rip->i_num);
rip->i_nlinks--; /* undo the increment done in new_node() */
}
- rip->i_dirt = DIRTY; /* either way, i_nlinks has changed */
+ IN_MARKDIRTY(rip); /* either way, i_nlinks has changed */
put_inode(ldirp); /* return the inode of the parent dir */
put_inode(rip); /* return the inode of the newly made dir */
/* New inode acquired. Try to make directory entry. */
if((r=search_dir(ldirp, string, &rip->i_num, ENTER, IGN_PERM)) != OK) {
rip->i_nlinks--; /* pity, have to free disk inode */
- rip->i_dirt = DIRTY; /* dirty inodes are written out */
+ IN_MARKDIRTY(rip); /* dirty inodes are written out */
put_inode(rip); /* this call frees the inode */
err_code = r;
return(NULL);
t = MFS_NAME_MAX - sizeof(ino_t);
*((ino_t *) &dp->mfs_d_name[t]) = dp->mfs_d_ino;
dp->mfs_d_ino = NO_ENTRY; /* erase entry */
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
ldir_ptr->i_update |= CTIME | MTIME;
- ldir_ptr->i_dirt = DIRTY;
+ IN_MARKDIRTY(ldir_ptr);
if (pos < ldir_ptr->i_last_dpos)
ldir_ptr->i_last_dpos = pos;
} else {
for (i = 0; i < MFS_NAME_MAX && string[i]; i++) dp->mfs_d_name[i] = string[i];
sp = ldir_ptr->i_sp;
dp->mfs_d_ino = conv4(sp->s_native, (int) *numb);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
put_block(bp, DIRECTORY_BLOCK);
ldir_ptr->i_update |= CTIME | MTIME; /* mark mtime for update later */
- ldir_ptr->i_dirt = DIRTY;
+ IN_MARKDIRTY(ldir_ptr);
if (new_slots > old_slots) {
ldir_ptr->i_size = (off_t) new_slots * DIR_ENTRY_SIZE;
/* Send the change to disk if the directory is extended. */
/* Now make the change. Clear setgid bit if file is not in caller's grp */
rip->i_mode = (rip->i_mode & ~ALL_MODES) | (mode & ALL_MODES);
rip->i_update |= CTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
/* Return full new mode to caller. */
fs_m_out.RES_MODE = rip->i_mode;
rip->i_gid = (gid_t) fs_m_in.REQ_GID;
rip->i_mode &= ~(I_SET_UID_BIT | I_SET_GID_BIT);
rip->i_update |= CTIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
}
/* Update caller on current mode, as it may have changed. */
if (r == OK) {
if (rw_flag == READING) rip->i_update |= ATIME;
if (rw_flag == WRITING) rip->i_update |= CTIME | MTIME;
- rip->i_dirt = DIRTY; /* inode is thus now dirty */
+ IN_MARKDIRTY(rip); /* inode is thus now dirty */
}
fs_m_out.RES_NBYTES = cum_io;
/* Copy a chunk from user space to the block buffer. */
r = sys_safecopyfrom(VFS_PROC_NR, gid, (vir_bytes) buf_off,
(vir_bytes) (bp->b_data+off), (size_t) chunk, D);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
}
n = (off + chunk == block_size ? FULL_DATA_BLOCK : PARTIAL_DATA_BLOCK);
fs_m_out.RES_NBYTES = userbuf_off;
fs_m_out.RES_SEEK_POS_LO = new_pos;
rip->i_update |= ATIME;
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
r = OK;
}
/* Allocate and return bit number. */
k |= 1 << i;
*wptr = (bitchunk_t) conv4(sp->s_native, (int) k);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
put_block(bp, MAP_BLOCK);
return(b);
}
k &= ~mask;
bp->b_bitmap[word] = (bitchunk_t) conv4(sp->s_native, (int) k);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
put_block(bp, MAP_BLOCK);
}
rip->i_atime = fs_m_in.REQ_ACTIME;
rip->i_mtime = fs_m_in.REQ_MODTIME;
rip->i_update = CTIME; /* discard any stale ATIME and MTIME flags */
- rip->i_dirt = DIRTY;
+ IN_MARKDIRTY(rip);
}
put_inode(rip);
struct buf *b_hash; /* used to link bufs on hash chains */
block_t b_blocknr; /* block number of its (minor) device */
dev_t b_dev; /* major | minor device where block resides */
- char b_dirt; /* CLEAN or DIRTY */
+ char b_dirt; /* BP_CLEAN or BP_DIRTY */
char b_count; /* number of users of this buffer */
unsigned int b_bytes; /* Number of bytes allocated in bp */
};
long excess, zone;
struct buf *bp_dindir = NULL, *bp = NULL;
- rip->i_dirt = DIRTY; /* inode will be changed */
+ IN_MARKDIRTY(rip);
scale = rip->i_sp->s_log_zone_size; /* for zone-block conversion */
/* relative zone # to insert */
zone = (position/rip->i_sp->s_block_size) >> scale;
new_ind = TRUE;
/* If double ind, it is dirty. */
- if (bp_dindir != NULL) bp_dindir->b_dirt = DIRTY;
+ if (bp_dindir != NULL) MARKDIRTY(bp_dindir);
if (z1 == NO_ZONE) {
/* Release dbl indirect blk. */
put_block(bp_dindir, INDIRECT_BLOCK);
rip->i_zone[zones] = z1;
} else {
wr_indir(bp_dindir, ind_ex, z1);
- bp_dindir->b_dirt = DIRTY;
+ MARKDIRTY(bp_dindir);
}
}
} else {
wr_indir(bp, ex, new_zone);
}
/* z1 equals NO_ZONE only when we are freeing up the indirect block. */
- bp->b_dirt = (z1 == NO_ZONE) ? CLEAN : DIRTY;
+ if(z1 == NO_ZONE) { MARKCLEAN(bp); } else { MARKDIRTY(bp); }
put_block(bp, INDIRECT_BLOCK);
}
*/
if(z1 == NO_ZONE && !single && z2 != NO_ZONE &&
empty_indir(bp_dindir, rip->i_sp)) {
- bp_dindir->b_dirt = CLEAN;
+ MARKCLEAN(bp_dindir);
free_zone(rip->i_dev, z2);
rip->i_zone[zones+1] = NO_ZONE;
}
ASSERT(bp->b_bytes > 0);
ASSERT(bp->bp);
memset(bp->b_data, 0, (size_t) bp->b_bytes);
- bp->b_dirt = DIRTY;
+ MARKDIRTY(bp);
}