xref: /minix/minix/fs/ext2/misc.c (revision 83133719)
1 /* Created (MFS based):
2  *   February 2010 (Evgeniy Ivanov)
3  */
4 
5 #include "fs.h"
6 #include "inode.h"
7 #include "super.h"
8 #include <assert.h>
9 
10 /*===========================================================================*
11  *				fs_sync					     *
12  *===========================================================================*/
13 void fs_sync(void)
14 {
15 /* Perform the sync() system call.  Flush all the tables.
16  * The order in which the various tables are flushed is critical.  The
17  * blocks must be flushed last, since rw_inode() leaves its results in
18  * the block cache.
19  */
20   struct inode *rip;
21 
22   assert(lmfs_nr_bufs() > 0);
23 
24   if (superblock->s_rd_only)
25 	return; /* nothing to sync */
26 
27   /* Write all the dirty inodes to the disk. */
28   for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
29 	if(rip->i_count > 0 && rip->i_dirt == IN_DIRTY) rw_inode(rip, WRITING);
30 
31   lmfs_flushall();
32 
33   if (superblock->s_dev != NO_DEV) {
34 	superblock->s_wtime = clock_time(NULL);
35 	write_super(superblock);
36   }
37 }
38