/*
|
/*
|
* linux/fs/minix/fsync.c
|
* linux/fs/minix/fsync.c
|
*
|
*
|
* Copyright (C) 1993 Stephen Tweedie (sct@dcs.ed.ac.uk)
|
* Copyright (C) 1993 Stephen Tweedie (sct@dcs.ed.ac.uk)
|
* from
|
* from
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
*
|
*
|
* Copyright (C) 1996 Gertjan van Wingerde (gertjan@cs.vu.nl)
|
* Copyright (C) 1996 Gertjan van Wingerde (gertjan@cs.vu.nl)
|
* Minix V2 fs support
|
* Minix V2 fs support
|
*
|
*
|
* minix fsync primitive
|
* minix fsync primitive
|
*/
|
*/
|
|
|
#include <linux/errno.h>
|
#include <linux/errno.h>
|
#include <linux/sched.h>
|
#include <linux/sched.h>
|
#include <linux/stat.h>
|
#include <linux/stat.h>
|
#include <linux/fcntl.h>
|
#include <linux/fcntl.h>
|
#include <linux/locks.h>
|
#include <linux/locks.h>
|
|
|
#include <linux/fs.h>
|
#include <linux/fs.h>
|
#include <linux/minix_fs.h>
|
#include <linux/minix_fs.h>
|
|
|
#include <asm/segment.h>
|
#include <asm/segment.h>
|
#include <asm/system.h>
|
#include <asm/system.h>
|
|
|
#define blocksize BLOCK_SIZE
|
#define blocksize BLOCK_SIZE
|
|
|
/*
|
/*
|
* The functions for minix V1 fs file synchronization.
|
* The functions for minix V1 fs file synchronization.
|
*/
|
*/
|
static int V1_sync_block (struct inode * inode, unsigned short * block, int wait)
|
static int V1_sync_block (struct inode * inode, unsigned short * block, int wait)
|
{
|
{
|
struct buffer_head * bh;
|
struct buffer_head * bh;
|
unsigned short tmp;
|
unsigned short tmp;
|
|
|
if (!*block)
|
if (!*block)
|
return 0;
|
return 0;
|
tmp = *block;
|
tmp = *block;
|
bh = get_hash_table(inode->i_dev, *block, blocksize);
|
bh = get_hash_table(inode->i_dev, *block, blocksize);
|
if (!bh)
|
if (!bh)
|
return 0;
|
return 0;
|
if (*block != tmp) {
|
if (*block != tmp) {
|
brelse (bh);
|
brelse (bh);
|
return 1;
|
return 1;
|
}
|
}
|
if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
|
if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
|
brelse(bh);
|
brelse(bh);
|
return -1;
|
return -1;
|
}
|
}
|
if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh))
|
if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh))
|
{
|
{
|
brelse(bh);
|
brelse(bh);
|
return 0;
|
return 0;
|
}
|
}
|
ll_rw_block(WRITE, 1, &bh);
|
ll_rw_block(WRITE, 1, &bh);
|
bh->b_count--;
|
bh->b_count--;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int V1_sync_iblock (struct inode * inode, unsigned short * iblock,
|
static int V1_sync_iblock (struct inode * inode, unsigned short * iblock,
|
struct buffer_head **bh, int wait)
|
struct buffer_head **bh, int wait)
|
{
|
{
|
int rc;
|
int rc;
|
unsigned short tmp;
|
unsigned short tmp;
|
|
|
*bh = NULL;
|
*bh = NULL;
|
tmp = *iblock;
|
tmp = *iblock;
|
if (!tmp)
|
if (!tmp)
|
return 0;
|
return 0;
|
rc = V1_sync_block (inode, iblock, wait);
|
rc = V1_sync_block (inode, iblock, wait);
|
if (rc)
|
if (rc)
|
return rc;
|
return rc;
|
*bh = bread(inode->i_dev, tmp, blocksize);
|
*bh = bread(inode->i_dev, tmp, blocksize);
|
if (tmp != *iblock) {
|
if (tmp != *iblock) {
|
brelse(*bh);
|
brelse(*bh);
|
*bh = NULL;
|
*bh = NULL;
|
return 1;
|
return 1;
|
}
|
}
|
if (!*bh)
|
if (!*bh)
|
return -1;
|
return -1;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int V1_sync_direct(struct inode *inode, int wait)
|
static int V1_sync_direct(struct inode *inode, int wait)
|
{
|
{
|
int i;
|
int i;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
for (i = 0; i < 7; i++) {
|
for (i = 0; i < 7; i++) {
|
rc = V1_sync_block (inode,
|
rc = V1_sync_block (inode,
|
(unsigned short *) inode->u.minix_i.u.i1_data + i, wait);
|
(unsigned short *) inode->u.minix_i.u.i1_data + i, wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
return err;
|
return err;
|
}
|
}
|
|
|
static int V1_sync_indirect(struct inode *inode, unsigned short *iblock, int wait)
|
static int V1_sync_indirect(struct inode *inode, unsigned short *iblock, int wait)
|
{
|
{
|
int i;
|
int i;
|
struct buffer_head * ind_bh;
|
struct buffer_head * ind_bh;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
rc = V1_sync_iblock (inode, iblock, &ind_bh, wait);
|
rc = V1_sync_iblock (inode, iblock, &ind_bh, wait);
|
if (rc || !ind_bh)
|
if (rc || !ind_bh)
|
return rc;
|
return rc;
|
|
|
for (i = 0; i < 512; i++) {
|
for (i = 0; i < 512; i++) {
|
rc = V1_sync_block (inode,
|
rc = V1_sync_block (inode,
|
((unsigned short *) ind_bh->b_data) + i,
|
((unsigned short *) ind_bh->b_data) + i,
|
wait);
|
wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
brelse(ind_bh);
|
brelse(ind_bh);
|
return err;
|
return err;
|
}
|
}
|
|
|
static int V1_sync_dindirect(struct inode *inode, unsigned short *diblock,
|
static int V1_sync_dindirect(struct inode *inode, unsigned short *diblock,
|
int wait)
|
int wait)
|
{
|
{
|
int i;
|
int i;
|
struct buffer_head * dind_bh;
|
struct buffer_head * dind_bh;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
rc = V1_sync_iblock (inode, diblock, &dind_bh, wait);
|
rc = V1_sync_iblock (inode, diblock, &dind_bh, wait);
|
if (rc || !dind_bh)
|
if (rc || !dind_bh)
|
return rc;
|
return rc;
|
|
|
for (i = 0; i < 512; i++) {
|
for (i = 0; i < 512; i++) {
|
rc = V1_sync_indirect (inode,
|
rc = V1_sync_indirect (inode,
|
((unsigned short *) dind_bh->b_data) + i,
|
((unsigned short *) dind_bh->b_data) + i,
|
wait);
|
wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
brelse(dind_bh);
|
brelse(dind_bh);
|
return err;
|
return err;
|
}
|
}
|
|
|
int V1_minix_sync_file(struct inode * inode, struct file * file)
|
int V1_minix_sync_file(struct inode * inode, struct file * file)
|
{
|
{
|
int wait, err = 0;
|
int wait, err = 0;
|
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
S_ISLNK(inode->i_mode)))
|
S_ISLNK(inode->i_mode)))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
for (wait=0; wait<=1; wait++)
|
for (wait=0; wait<=1; wait++)
|
{
|
{
|
err |= V1_sync_direct(inode, wait);
|
err |= V1_sync_direct(inode, wait);
|
err |= V1_sync_indirect(inode, inode->u.minix_i.u.i1_data + 7, wait);
|
err |= V1_sync_indirect(inode, inode->u.minix_i.u.i1_data + 7, wait);
|
err |= V1_sync_dindirect(inode, inode->u.minix_i.u.i1_data + 8, wait);
|
err |= V1_sync_dindirect(inode, inode->u.minix_i.u.i1_data + 8, wait);
|
}
|
}
|
err |= minix_sync_inode (inode);
|
err |= minix_sync_inode (inode);
|
return (err < 0) ? -EIO : 0;
|
return (err < 0) ? -EIO : 0;
|
}
|
}
|
|
|
/*
|
/*
|
* The functions for minix V2 fs file synchronization.
|
* The functions for minix V2 fs file synchronization.
|
*/
|
*/
|
static int V2_sync_block (struct inode * inode, unsigned long * block, int wait)
|
static int V2_sync_block (struct inode * inode, unsigned long * block, int wait)
|
{
|
{
|
struct buffer_head * bh;
|
struct buffer_head * bh;
|
unsigned long tmp;
|
unsigned long tmp;
|
|
|
if (!*block)
|
if (!*block)
|
return 0;
|
return 0;
|
tmp = *block;
|
tmp = *block;
|
bh = get_hash_table(inode->i_dev, *block, blocksize);
|
bh = get_hash_table(inode->i_dev, *block, blocksize);
|
if (!bh)
|
if (!bh)
|
return 0;
|
return 0;
|
if (*block != tmp) {
|
if (*block != tmp) {
|
brelse (bh);
|
brelse (bh);
|
return 1;
|
return 1;
|
}
|
}
|
if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
|
if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
|
brelse(bh);
|
brelse(bh);
|
return -1;
|
return -1;
|
}
|
}
|
if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh))
|
if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh))
|
{
|
{
|
brelse(bh);
|
brelse(bh);
|
return 0;
|
return 0;
|
}
|
}
|
ll_rw_block(WRITE, 1, &bh);
|
ll_rw_block(WRITE, 1, &bh);
|
bh->b_count--;
|
bh->b_count--;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int V2_sync_iblock (struct inode * inode, unsigned long * iblock,
|
static int V2_sync_iblock (struct inode * inode, unsigned long * iblock,
|
struct buffer_head **bh, int wait)
|
struct buffer_head **bh, int wait)
|
{
|
{
|
int rc;
|
int rc;
|
unsigned long tmp;
|
unsigned long tmp;
|
|
|
*bh = NULL;
|
*bh = NULL;
|
tmp = *iblock;
|
tmp = *iblock;
|
if (!tmp)
|
if (!tmp)
|
return 0;
|
return 0;
|
rc = V2_sync_block (inode, iblock, wait);
|
rc = V2_sync_block (inode, iblock, wait);
|
if (rc)
|
if (rc)
|
return rc;
|
return rc;
|
*bh = bread(inode->i_dev, tmp, blocksize);
|
*bh = bread(inode->i_dev, tmp, blocksize);
|
if (tmp != *iblock) {
|
if (tmp != *iblock) {
|
brelse(*bh);
|
brelse(*bh);
|
*bh = NULL;
|
*bh = NULL;
|
return 1;
|
return 1;
|
}
|
}
|
if (!*bh)
|
if (!*bh)
|
return -1;
|
return -1;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int V2_sync_direct(struct inode *inode, int wait)
|
static int V2_sync_direct(struct inode *inode, int wait)
|
{
|
{
|
int i;
|
int i;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
for (i = 0; i < 7; i++) {
|
for (i = 0; i < 7; i++) {
|
rc = V2_sync_block (inode,
|
rc = V2_sync_block (inode,
|
(unsigned long *)inode->u.minix_i.u.i2_data + i, wait);
|
(unsigned long *)inode->u.minix_i.u.i2_data + i, wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
return err;
|
return err;
|
}
|
}
|
|
|
static int V2_sync_indirect(struct inode *inode, unsigned long *iblock, int wait)
|
static int V2_sync_indirect(struct inode *inode, unsigned long *iblock, int wait)
|
{
|
{
|
int i;
|
int i;
|
struct buffer_head * ind_bh;
|
struct buffer_head * ind_bh;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
rc = V2_sync_iblock (inode, iblock, &ind_bh, wait);
|
rc = V2_sync_iblock (inode, iblock, &ind_bh, wait);
|
if (rc || !ind_bh)
|
if (rc || !ind_bh)
|
return rc;
|
return rc;
|
|
|
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
rc = V2_sync_block (inode,
|
rc = V2_sync_block (inode,
|
((unsigned long *) ind_bh->b_data) + i,
|
((unsigned long *) ind_bh->b_data) + i,
|
wait);
|
wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
brelse(ind_bh);
|
brelse(ind_bh);
|
return err;
|
return err;
|
}
|
}
|
|
|
static int V2_sync_dindirect(struct inode *inode, unsigned long *diblock,
|
static int V2_sync_dindirect(struct inode *inode, unsigned long *diblock,
|
int wait)
|
int wait)
|
{
|
{
|
int i;
|
int i;
|
struct buffer_head * dind_bh;
|
struct buffer_head * dind_bh;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
rc = V2_sync_iblock (inode, diblock, &dind_bh, wait);
|
rc = V2_sync_iblock (inode, diblock, &dind_bh, wait);
|
if (rc || !dind_bh)
|
if (rc || !dind_bh)
|
return rc;
|
return rc;
|
|
|
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
rc = V2_sync_indirect (inode,
|
rc = V2_sync_indirect (inode,
|
((unsigned long *) dind_bh->b_data) + i,
|
((unsigned long *) dind_bh->b_data) + i,
|
wait);
|
wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
brelse(dind_bh);
|
brelse(dind_bh);
|
return err;
|
return err;
|
}
|
}
|
|
|
static int V2_sync_tindirect(struct inode *inode, unsigned long *tiblock,
|
static int V2_sync_tindirect(struct inode *inode, unsigned long *tiblock,
|
int wait)
|
int wait)
|
{
|
{
|
int i;
|
int i;
|
struct buffer_head * tind_bh;
|
struct buffer_head * tind_bh;
|
int rc, err = 0;
|
int rc, err = 0;
|
|
|
rc = V2_sync_iblock (inode, tiblock, &tind_bh, wait);
|
rc = V2_sync_iblock (inode, tiblock, &tind_bh, wait);
|
if (rc || !tind_bh)
|
if (rc || !tind_bh)
|
return rc;
|
return rc;
|
|
|
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
rc = V2_sync_dindirect (inode,
|
rc = V2_sync_dindirect (inode,
|
((unsigned long *) tind_bh->b_data) + i,
|
((unsigned long *) tind_bh->b_data) + i,
|
wait);
|
wait);
|
if (rc > 0)
|
if (rc > 0)
|
break;
|
break;
|
if (rc)
|
if (rc)
|
err = rc;
|
err = rc;
|
}
|
}
|
brelse(tind_bh);
|
brelse(tind_bh);
|
return err;
|
return err;
|
}
|
}
|
|
|
int V2_minix_sync_file(struct inode * inode, struct file * file)
|
int V2_minix_sync_file(struct inode * inode, struct file * file)
|
{
|
{
|
int wait, err = 0;
|
int wait, err = 0;
|
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
S_ISLNK(inode->i_mode)))
|
S_ISLNK(inode->i_mode)))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
for (wait=0; wait<=1; wait++)
|
for (wait=0; wait<=1; wait++)
|
{
|
{
|
err |= V2_sync_direct(inode, wait);
|
err |= V2_sync_direct(inode, wait);
|
err |= V2_sync_indirect(inode,
|
err |= V2_sync_indirect(inode,
|
(unsigned long *) inode->u.minix_i.u.i2_data + 7, wait);
|
(unsigned long *) inode->u.minix_i.u.i2_data + 7, wait);
|
err |= V2_sync_dindirect(inode,
|
err |= V2_sync_dindirect(inode,
|
(unsigned long *) inode->u.minix_i.u.i2_data + 8, wait);
|
(unsigned long *) inode->u.minix_i.u.i2_data + 8, wait);
|
err |= V2_sync_tindirect(inode,
|
err |= V2_sync_tindirect(inode,
|
(unsigned long *) inode->u.minix_i.u.i2_data + 9, wait);
|
(unsigned long *) inode->u.minix_i.u.i2_data + 9, wait);
|
}
|
}
|
err |= minix_sync_inode (inode);
|
err |= minix_sync_inode (inode);
|
return (err < 0) ? -EIO : 0;
|
return (err < 0) ? -EIO : 0;
|
}
|
}
|
|
|
/*
|
/*
|
* The function which is called for file synchronization.
|
* The function which is called for file synchronization.
|
*/
|
*/
|
int minix_sync_file(struct inode * inode, struct file * file)
|
int minix_sync_file(struct inode * inode, struct file * file)
|
{
|
{
|
if (INODE_VERSION(inode) == MINIX_V1)
|
if (INODE_VERSION(inode) == MINIX_V1)
|
return V1_minix_sync_file(inode, file);
|
return V1_minix_sync_file(inode, file);
|
else
|
else
|
return V2_minix_sync_file(inode, file);
|
return V2_minix_sync_file(inode, file);
|
}
|
}
|
|
|