/* ufs_subr.c 6.1 83/07/29 */
* Update is the internal name of 'sync'. It goes through the disk
* queues to initiate sandbagged IO; goes through the inodes to write
* modified nodes; and it goes through the mount table to initiate
* the writing of the modified super blocks.
register struct inode
*ip
;
register struct mount
*mp
;
* Write back modified superblocks.
* Consistency check that the superblock
* of each file system is still in the buffer cache.
for (mp
= &mount
[0]; mp
< &mount
[NMOUNT
]; mp
++) {
if (mp
->m_bufp
== NULL
|| mp
->m_dev
== NODEV
)
fs
= mp
->m_bufp
->b_un
.b_fs
;
if (fs
->fs_ronly
!= 0) { /* XXX */
printf("fs = %s\n", fs
->fs_fsmnt
);
panic("update: rofs mod");
fs
->fs_time
= time
.tv_sec
;
* Write back each (modified) inode.
for (ip
= inode
; ip
< inodeNINODE
; ip
++) {
if ((ip
->i_flag
& ILOCKED
) != 0 || ip
->i_count
== 0)
iupdat(ip
, &time
, &time
, 0);
* Force stale buffer cache information to be flushed,
* Flush all the blocks associated with an inode.
* Note that we make a more stringent check of
* writing out any block in the buffer pool that may
* overlap the inode. This brings the inode up to
* date with recent mods to the cooked device.
register struct inode
*ip
;
lastlbn
= howmany(ip
->i_size
, fs
->fs_bsize
);
for (lbn
= 0; lbn
< lastlbn
; lbn
++) {
blkno
= fsbtodb(fs
, bmap(ip
, lbn
, B_READ
));
blkflush(ip
->i_dev
, blkno
, blksize(fs
, ip
, lbn
));
iupdat(ip
, &time
, &time
, 1);
extern u_char
*fragtbl
[];
* Update the frsum fields to reflect addition or deletion
fragacct(fs
, fragmap
, fraglist
, cnt
)
register int field
, subfield
;
inblk
= (int)(fragtbl
[fs
->fs_frag
][fragmap
]) << 1;
for (siz
= 1; siz
< fs
->fs_frag
; siz
++) {
if ((inblk
& (1 << (siz
+ (fs
->fs_frag
% NBBY
)))) == 0)
for (pos
= siz
; pos
<= fs
->fs_frag
; pos
++) {
if ((fragmap
& field
) == subfield
) {
* Check that a specified block number is in range.
if ((unsigned)bn
>= fs
->fs_size
) {
printf("bad block %d, ", bn
);
* check if a block is available
mask
= 0x0f << ((h
& 0x1) << 2);
return ((cp
[h
>> 1] & mask
) == mask
);
mask
= 0x03 << ((h
& 0x3) << 1);
return ((cp
[h
>> 2] & mask
) == mask
);
mask
= 0x01 << (h
& 0x7);
return ((cp
[h
>> 3] & mask
) == mask
);
* take a block out of the map
cp
[h
>> 1] &= ~(0x0f << ((h
& 0x1) << 2));
cp
[h
>> 2] &= ~(0x03 << ((h
& 0x3) << 1));
cp
[h
>> 3] &= ~(0x01 << (h
& 0x7));
* put a block into the map
cp
[h
>> 1] |= (0x0f << ((h
& 0x1) << 2));
cp
[h
>> 2] |= (0x03 << ((h
& 0x3) << 1));
cp
[h
>> 3] |= (0x01 << (h
& 0x7));
* Getfs maps a device number into a pointer to the incore super block.
* The algorithm is a linear search through the mount table. A
* consistency check of the super block magic number is performed.
* panic: no fs -- the device is not mounted.
register struct mount
*mp
;
for (mp
= &mount
[0]; mp
< &mount
[NMOUNT
]; mp
++) {
if (mp
->m_bufp
== NULL
|| mp
->m_dev
!= dev
)
fs
= mp
->m_bufp
->b_un
.b_fs
;
if (fs
->fs_magic
!= FS_MAGIC
) {
printf("dev = 0x%x, fs = %s\n", dev
, fs
->fs_fsmnt
);
panic("getfs: bad magic");
printf("dev = 0x%x\n", dev
);
* Getfsx returns the index in the file system
* table of the specified device. The swap device
* is also assigned a pseudo-index. The index may
* be used as a compressed indication of the location
* provided the information need remain valid only
* as long as the file system is mounted.
register struct mount
*mp
;
for(mp
= &mount
[0]; mp
< &mount
[NMOUNT
]; mp
++)
* Print out statistics on the current allocation of the buffer pool.
* Can be enabled to print out on every ``sync'' by setting "syncprt"
register struct buf
*bp
, *dp
;
int counts
[MAXBSIZE
/CLBYTES
+1];
static char *bname
[BQUEUES
] = { "LOCKED", "LRU", "AGE", "EMPTY" };
for (bp
= bfreelist
, i
= 0; bp
< &bfreelist
[BQUEUES
]; bp
++, i
++) {
for (j
= 0; j
<= MAXBSIZE
/CLBYTES
; j
++)
for (dp
= bp
->av_forw
; dp
!= bp
; dp
= dp
->av_forw
) {
counts
[dp
->b_bufsize
/CLBYTES
]++;
printf("%s: total-%d", bname
[i
], count
);
for (j
= 0; j
<= MAXBSIZE
/CLBYTES
; j
++)
printf(", %d-%d", j
* CLBYTES
, counts
[j
]);