OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [xiafs/] [inode.c] - Diff between revs 1765 and 1782

Only display areas with differences | Details | Blame | View Log

Rev 1765 Rev 1782
/*
/*
 *  linux/fs/xiafs/inode.c
 *  linux/fs/xiafs/inode.c
 *
 *
 *  Copyright (C) Q. Frank Xia, 1993.
 *  Copyright (C) Q. Frank Xia, 1993.
 *
 *
 *  Based on Linus' minix/inode.c
 *  Based on Linus' minix/inode.c
 *  Copyright (C) Linus Torvalds, 1991, 1992.
 *  Copyright (C) Linus Torvalds, 1991, 1992.
 *
 *
 *  This software may be redistributed per Linux Copyright.
 *  This software may be redistributed per Linux Copyright.
 */
 */
 
 
#include <linux/module.h>
#include <linux/module.h>
 
 
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/xia_fs.h>
#include <linux/xia_fs.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/stat.h>
#include <linux/locks.h>
#include <linux/locks.h>
#include <asm/system.h>
#include <asm/system.h>
#include <asm/segment.h>
#include <asm/segment.h>
 
 
#include "xiafs_mac.h"
#include "xiafs_mac.h"
 
 
static u_long random_nr;
static u_long random_nr;
 
 
void xiafs_put_inode(struct inode *inode)
void xiafs_put_inode(struct inode *inode)
{
{
    if (inode->i_nlink)
    if (inode->i_nlink)
        return;
        return;
    inode->i_size = 0;
    inode->i_size = 0;
    xiafs_truncate(inode);
    xiafs_truncate(inode);
    xiafs_free_inode(inode);
    xiafs_free_inode(inode);
}
}
 
 
void xiafs_put_super(struct super_block *sb)
void xiafs_put_super(struct super_block *sb)
{
{
    int i;
    int i;
 
 
    lock_super(sb);
    lock_super(sb);
    sb->s_dev = 0;
    sb->s_dev = 0;
    for(i = 0 ; i < _XIAFS_IMAP_SLOTS ; i++)
    for(i = 0 ; i < _XIAFS_IMAP_SLOTS ; i++)
        brelse(sb->u.xiafs_sb.s_imap_buf[i]);
        brelse(sb->u.xiafs_sb.s_imap_buf[i]);
    for(i = 0 ; i < _XIAFS_ZMAP_SLOTS ; i++)
    for(i = 0 ; i < _XIAFS_ZMAP_SLOTS ; i++)
        brelse(sb->u.xiafs_sb.s_zmap_buf[i]);
        brelse(sb->u.xiafs_sb.s_zmap_buf[i]);
    unlock_super(sb);
    unlock_super(sb);
    MOD_DEC_USE_COUNT;
    MOD_DEC_USE_COUNT;
}
}
 
 
static struct super_operations xiafs_sops = {
static struct super_operations xiafs_sops = {
    xiafs_read_inode,
    xiafs_read_inode,
    NULL,
    NULL,
    xiafs_write_inode,
    xiafs_write_inode,
    xiafs_put_inode,
    xiafs_put_inode,
    xiafs_put_super,
    xiafs_put_super,
    NULL,
    NULL,
    xiafs_statfs,
    xiafs_statfs,
    NULL
    NULL
};
};
 
 
struct super_block *xiafs_read_super(struct super_block *s, void *data,
struct super_block *xiafs_read_super(struct super_block *s, void *data,
                                     int silent)
                                     int silent)
{
{
    struct buffer_head *bh;
    struct buffer_head *bh;
    struct xiafs_super_block *sp;
    struct xiafs_super_block *sp;
    int i, z;
    int i, z;
    kdev_t dev;
    kdev_t dev;
 
 
    MOD_INC_USE_COUNT;
    MOD_INC_USE_COUNT;
    dev = s->s_dev;
    dev = s->s_dev;
    lock_super(s);
    lock_super(s);
 
 
    set_blocksize(dev, BLOCK_SIZE);
    set_blocksize(dev, BLOCK_SIZE);
 
 
    if (!(bh = bread(dev, 0, BLOCK_SIZE))) {
    if (!(bh = bread(dev, 0, BLOCK_SIZE))) {
        s->s_dev = 0;
        s->s_dev = 0;
        unlock_super(s);
        unlock_super(s);
        printk("XIA-FS: read super_block failed (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: read super_block failed (%s %d)\n", WHERE_ERR);
        MOD_DEC_USE_COUNT;
        MOD_DEC_USE_COUNT;
        return NULL;
        return NULL;
    }
    }
    sp = (struct xiafs_super_block *) bh->b_data;
    sp = (struct xiafs_super_block *) bh->b_data;
    s->s_magic = sp->s_magic;
    s->s_magic = sp->s_magic;
    if (s->s_magic != _XIAFS_SUPER_MAGIC) {
    if (s->s_magic != _XIAFS_SUPER_MAGIC) {
        s->s_dev = 0;
        s->s_dev = 0;
        unlock_super(s);
        unlock_super(s);
        brelse(bh);
        brelse(bh);
        if (!silent)
        if (!silent)
                printk("VFS: Can't find a xiafs filesystem on dev "
                printk("VFS: Can't find a xiafs filesystem on dev "
                       "%s.\n", kdevname(dev));
                       "%s.\n", kdevname(dev));
        MOD_DEC_USE_COUNT;
        MOD_DEC_USE_COUNT;
        return NULL;
        return NULL;
    }
    }
    s->s_blocksize = sp->s_zone_size;
    s->s_blocksize = sp->s_zone_size;
    s->s_blocksize_bits = 10 + sp->s_zone_shift;
    s->s_blocksize_bits = 10 + sp->s_zone_shift;
    if (s->s_blocksize != BLOCK_SIZE &&
    if (s->s_blocksize != BLOCK_SIZE &&
        (s->s_blocksize == 1024 || s->s_blocksize == 2048 ||
        (s->s_blocksize == 1024 || s->s_blocksize == 2048 ||
         s->s_blocksize == 4096)) {
         s->s_blocksize == 4096)) {
      brelse(bh);
      brelse(bh);
      set_blocksize(dev, s->s_blocksize);
      set_blocksize(dev, s->s_blocksize);
      bh = bread (dev, 0,  s->s_blocksize);
      bh = bread (dev, 0,  s->s_blocksize);
      if(!bh) {
      if(!bh) {
        MOD_DEC_USE_COUNT;
        MOD_DEC_USE_COUNT;
        return NULL;
        return NULL;
      }
      }
      sp = (struct xiafs_super_block *) (((char *)bh->b_data) + BLOCK_SIZE) ;
      sp = (struct xiafs_super_block *) (((char *)bh->b_data) + BLOCK_SIZE) ;
    };
    };
    s->u.xiafs_sb.s_nzones = sp->s_nzones;
    s->u.xiafs_sb.s_nzones = sp->s_nzones;
    s->u.xiafs_sb.s_ninodes = sp->s_ninodes;
    s->u.xiafs_sb.s_ninodes = sp->s_ninodes;
    s->u.xiafs_sb.s_ndatazones = sp->s_ndatazones;
    s->u.xiafs_sb.s_ndatazones = sp->s_ndatazones;
    s->u.xiafs_sb.s_imap_zones = sp->s_imap_zones;
    s->u.xiafs_sb.s_imap_zones = sp->s_imap_zones;
    s->u.xiafs_sb.s_zmap_zones = sp->s_zmap_zones;
    s->u.xiafs_sb.s_zmap_zones = sp->s_zmap_zones;
    s->u.xiafs_sb.s_firstdatazone = sp->s_firstdatazone;
    s->u.xiafs_sb.s_firstdatazone = sp->s_firstdatazone;
    s->u.xiafs_sb.s_zone_shift = sp->s_zone_shift;
    s->u.xiafs_sb.s_zone_shift = sp->s_zone_shift;
    s->u.xiafs_sb.s_max_size = sp->s_max_size;
    s->u.xiafs_sb.s_max_size = sp->s_max_size;
    brelse(bh);
    brelse(bh);
    for (i=0;i < _XIAFS_IMAP_SLOTS;i++) {
    for (i=0;i < _XIAFS_IMAP_SLOTS;i++) {
        s->u.xiafs_sb.s_imap_buf[i] = NULL;
        s->u.xiafs_sb.s_imap_buf[i] = NULL;
        s->u.xiafs_sb.s_imap_iznr[i] = -1;
        s->u.xiafs_sb.s_imap_iznr[i] = -1;
    }
    }
    for (i=0;i < _XIAFS_ZMAP_SLOTS;i++) {
    for (i=0;i < _XIAFS_ZMAP_SLOTS;i++) {
        s->u.xiafs_sb.s_zmap_buf[i] = NULL;
        s->u.xiafs_sb.s_zmap_buf[i] = NULL;
        s->u.xiafs_sb.s_zmap_zznr[i] = -1;
        s->u.xiafs_sb.s_zmap_zznr[i] = -1;
    }
    }
    z=1;
    z=1;
    if ( s->u.xiafs_sb.s_imap_zones > _XIAFS_IMAP_SLOTS )
    if ( s->u.xiafs_sb.s_imap_zones > _XIAFS_IMAP_SLOTS )
        s->u.xiafs_sb.s_imap_cached=1;
        s->u.xiafs_sb.s_imap_cached=1;
    else {
    else {
        s->u.xiafs_sb.s_imap_cached=0;
        s->u.xiafs_sb.s_imap_cached=0;
        for (i=0 ; i < s->u.xiafs_sb.s_imap_zones ; i++) {
        for (i=0 ; i < s->u.xiafs_sb.s_imap_zones ; i++) {
            if (!(s->u.xiafs_sb.s_imap_buf[i]=bread(dev, z++, XIAFS_ZSIZE(s))))
            if (!(s->u.xiafs_sb.s_imap_buf[i]=bread(dev, z++, XIAFS_ZSIZE(s))))
                goto xiafs_read_super_fail;
                goto xiafs_read_super_fail;
            s->u.xiafs_sb.s_imap_iznr[i]=i;
            s->u.xiafs_sb.s_imap_iznr[i]=i;
        }
        }
    }
    }
    if ( s->u.xiafs_sb.s_zmap_zones > _XIAFS_ZMAP_SLOTS )
    if ( s->u.xiafs_sb.s_zmap_zones > _XIAFS_ZMAP_SLOTS )
        s->u.xiafs_sb.s_zmap_cached=1;
        s->u.xiafs_sb.s_zmap_cached=1;
    else {
    else {
        s->u.xiafs_sb.s_zmap_cached=0;
        s->u.xiafs_sb.s_zmap_cached=0;
        for (i=0 ; i < s->u.xiafs_sb.s_zmap_zones ; i++) {
        for (i=0 ; i < s->u.xiafs_sb.s_zmap_zones ; i++) {
            if (!(s->u.xiafs_sb.s_zmap_buf[i]=bread(dev, z++, XIAFS_ZSIZE(s))))
            if (!(s->u.xiafs_sb.s_zmap_buf[i]=bread(dev, z++, XIAFS_ZSIZE(s))))
                goto xiafs_read_super_fail;
                goto xiafs_read_super_fail;
            s->u.xiafs_sb.s_zmap_zznr[i]=i;
            s->u.xiafs_sb.s_zmap_zznr[i]=i;
        }
        }
    }
    }
    /* set up enough so that it can read an inode */
    /* set up enough so that it can read an inode */
    s->s_dev = dev;
    s->s_dev = dev;
    s->s_op = &xiafs_sops;
    s->s_op = &xiafs_sops;
    s->s_mounted = iget(s, _XIAFS_ROOT_INO);
    s->s_mounted = iget(s, _XIAFS_ROOT_INO);
    if (!s->s_mounted)
    if (!s->s_mounted)
        goto xiafs_read_super_fail;
        goto xiafs_read_super_fail;
    unlock_super(s);
    unlock_super(s);
    random_nr=CURRENT_TIME;
    random_nr=CURRENT_TIME;
    return s;
    return s;
 
 
xiafs_read_super_fail:
xiafs_read_super_fail:
    for(i=0; i < _XIAFS_IMAP_SLOTS; i++)
    for(i=0; i < _XIAFS_IMAP_SLOTS; i++)
        brelse(s->u.xiafs_sb.s_imap_buf[i]);
        brelse(s->u.xiafs_sb.s_imap_buf[i]);
    for(i=0; i < _XIAFS_ZMAP_SLOTS; i++)
    for(i=0; i < _XIAFS_ZMAP_SLOTS; i++)
        brelse(s->u.xiafs_sb.s_zmap_buf[i]);
        brelse(s->u.xiafs_sb.s_zmap_buf[i]);
    s->s_dev = 0;
    s->s_dev = 0;
    unlock_super(s);
    unlock_super(s);
    printk("XIA-FS: read bitmaps failed (%s %d)\n", WHERE_ERR);
    printk("XIA-FS: read bitmaps failed (%s %d)\n", WHERE_ERR);
    MOD_DEC_USE_COUNT;
    MOD_DEC_USE_COUNT;
    return NULL;
    return NULL;
}
}
 
 
void xiafs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
void xiafs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
{
{
        struct statfs tmp;
        struct statfs tmp;
 
 
        tmp.f_type = _XIAFS_SUPER_MAGIC;
        tmp.f_type = _XIAFS_SUPER_MAGIC;
        tmp.f_bsize = XIAFS_ZSIZE(sb);
        tmp.f_bsize = XIAFS_ZSIZE(sb);
        tmp.f_blocks = sb->u.xiafs_sb.s_ndatazones;
        tmp.f_blocks = sb->u.xiafs_sb.s_ndatazones;
        tmp.f_bfree = xiafs_count_free_zones(sb);
        tmp.f_bfree = xiafs_count_free_zones(sb);
        tmp.f_bavail = tmp.f_bfree;
        tmp.f_bavail = tmp.f_bfree;
        tmp.f_files = sb->u.xiafs_sb.s_ninodes;
        tmp.f_files = sb->u.xiafs_sb.s_ninodes;
        tmp.f_ffree = xiafs_count_free_inodes(sb);
        tmp.f_ffree = xiafs_count_free_inodes(sb);
        tmp.f_namelen = _XIAFS_NAME_LEN;
        tmp.f_namelen = _XIAFS_NAME_LEN;
        memcpy_tofs(buf, &tmp, bufsiz);
        memcpy_tofs(buf, &tmp, bufsiz);
}
}
 
 
static int zone_bmap(struct buffer_head * bh, int nr)
static int zone_bmap(struct buffer_head * bh, int nr)
{
{
    int tmp;
    int tmp;
 
 
    if (!bh)
    if (!bh)
        return 0;
        return 0;
    tmp = ((u_long *) bh->b_data)[nr];
    tmp = ((u_long *) bh->b_data)[nr];
    brelse(bh);
    brelse(bh);
    return tmp;
    return tmp;
}
}
 
 
int xiafs_bmap(struct inode * inode,int zone)
int xiafs_bmap(struct inode * inode,int zone)
{
{
    int i;
    int i;
 
 
    if (zone < 0) {
    if (zone < 0) {
        printk("XIA-FS: block < 0 (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: block < 0 (%s %d)\n", WHERE_ERR);
        return 0;
        return 0;
    }
    }
    if (zone >= 8+(1+XIAFS_ADDRS_PER_Z(inode->i_sb))*XIAFS_ADDRS_PER_Z(inode->i_sb)) {
    if (zone >= 8+(1+XIAFS_ADDRS_PER_Z(inode->i_sb))*XIAFS_ADDRS_PER_Z(inode->i_sb)) {
        printk("XIA-FS: zone > big (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: zone > big (%s %d)\n", WHERE_ERR);
        return 0;
        return 0;
    }
    }
    if (!IS_RDONLY (inode)) {
    if (!IS_RDONLY (inode)) {
        inode->i_atime = CURRENT_TIME;
        inode->i_atime = CURRENT_TIME;
        inode->i_dirt = 1;
        inode->i_dirt = 1;
    }
    }
    if (zone < 8)
    if (zone < 8)
        return inode->u.xiafs_i.i_zone[zone];
        return inode->u.xiafs_i.i_zone[zone];
    zone -= 8;
    zone -= 8;
    if (zone < XIAFS_ADDRS_PER_Z(inode->i_sb)) {
    if (zone < XIAFS_ADDRS_PER_Z(inode->i_sb)) {
        i = inode->u.xiafs_i.i_ind_zone;
        i = inode->u.xiafs_i.i_ind_zone;
        if (i)
        if (i)
            i = zone_bmap(bread(inode->i_dev, i, XIAFS_ZSIZE(inode->i_sb)), zone);
            i = zone_bmap(bread(inode->i_dev, i, XIAFS_ZSIZE(inode->i_sb)), zone);
        return i;
        return i;
    }
    }
    zone -= XIAFS_ADDRS_PER_Z(inode->i_sb);
    zone -= XIAFS_ADDRS_PER_Z(inode->i_sb);
    i = inode->u.xiafs_i.i_dind_zone;
    i = inode->u.xiafs_i.i_dind_zone;
    if (i)
    if (i)
      i = zone_bmap(bread(inode->i_dev, i, XIAFS_ZSIZE(inode->i_sb)),
      i = zone_bmap(bread(inode->i_dev, i, XIAFS_ZSIZE(inode->i_sb)),
                    zone >> XIAFS_ADDRS_PER_Z_BITS(inode->i_sb));
                    zone >> XIAFS_ADDRS_PER_Z_BITS(inode->i_sb));
    if (i)
    if (i)
      i= zone_bmap(bread(inode->i_dev,i, XIAFS_ZSIZE(inode->i_sb)),
      i= zone_bmap(bread(inode->i_dev,i, XIAFS_ZSIZE(inode->i_sb)),
                   zone & (XIAFS_ADDRS_PER_Z(inode->i_sb)-1));
                   zone & (XIAFS_ADDRS_PER_Z(inode->i_sb)-1));
    return i;
    return i;
}
}
 
 
static u_long get_prev_addr(struct inode * inode, int zone)
static u_long get_prev_addr(struct inode * inode, int zone)
{
{
    u_long tmp;
    u_long tmp;
 
 
    if (zone > 0)
    if (zone > 0)
        while (--zone >= 0)              /* only files with holes suffer */
        while (--zone >= 0)              /* only files with holes suffer */
            if ((tmp=xiafs_bmap(inode, zone)))
            if ((tmp=xiafs_bmap(inode, zone)))
                return tmp;
                return tmp;
    random_nr=(random_nr+23)%inode->i_sb->u.xiafs_sb.s_ndatazones;
    random_nr=(random_nr+23)%inode->i_sb->u.xiafs_sb.s_ndatazones;
    return random_nr + inode->i_sb->u.xiafs_sb.s_firstdatazone;
    return random_nr + inode->i_sb->u.xiafs_sb.s_firstdatazone;
}
}
 
 
static struct buffer_head *
static struct buffer_head *
dt_getblk(struct inode * inode, u_long *lp, int create, u_long prev_addr)
dt_getblk(struct inode * inode, u_long *lp, int create, u_long prev_addr)
{
{
    int tmp;
    int tmp;
    struct buffer_head * result;
    struct buffer_head * result;
 
 
repeat:
repeat:
    if ((tmp=*lp)) {
    if ((tmp=*lp)) {
        result = getblk(inode->i_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
        result = getblk(inode->i_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
        if (tmp == *lp)
        if (tmp == *lp)
            return result;
            return result;
        brelse(result);
        brelse(result);
        goto repeat;
        goto repeat;
    }
    }
    if (!create)
    if (!create)
        return NULL;
        return NULL;
    tmp = xiafs_new_zone(inode->i_sb, prev_addr);
    tmp = xiafs_new_zone(inode->i_sb, prev_addr);
    if (!tmp)
    if (!tmp)
        return NULL;
        return NULL;
    result = getblk(inode->i_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
    result = getblk(inode->i_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
    if (*lp) {
    if (*lp) {
        xiafs_free_zone(inode->i_sb, tmp);
        xiafs_free_zone(inode->i_sb, tmp);
        brelse(result);
        brelse(result);
        goto repeat;
        goto repeat;
    }
    }
    *lp = tmp;
    *lp = tmp;
    inode->i_blocks+=2 << XIAFS_ZSHIFT(inode->i_sb);
    inode->i_blocks+=2 << XIAFS_ZSHIFT(inode->i_sb);
    return result;
    return result;
}
}
 
 
static struct buffer_head *
static struct buffer_head *
indt_getblk(struct inode * inode, struct buffer_head * bh,
indt_getblk(struct inode * inode, struct buffer_head * bh,
            int nr, int create, u_long prev_addr)
            int nr, int create, u_long prev_addr)
{
{
    int tmp;
    int tmp;
    u_long *lp;
    u_long *lp;
    struct buffer_head * result;
    struct buffer_head * result;
 
 
    if (!bh)
    if (!bh)
        return NULL;
        return NULL;
    if (!buffer_uptodate(bh)) {
    if (!buffer_uptodate(bh)) {
        ll_rw_block(READ, 1, &bh);
        ll_rw_block(READ, 1, &bh);
        wait_on_buffer(bh);
        wait_on_buffer(bh);
        if (!buffer_uptodate(bh)) {
        if (!buffer_uptodate(bh)) {
            brelse(bh);
            brelse(bh);
            return NULL;
            return NULL;
        }
        }
    }
    }
    lp = nr + (u_long *) bh->b_data;
    lp = nr + (u_long *) bh->b_data;
repeat:
repeat:
    if ((tmp=*lp)) {
    if ((tmp=*lp)) {
        result = getblk(bh->b_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
        result = getblk(bh->b_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
        if (tmp == *lp) {
        if (tmp == *lp) {
            brelse(bh);
            brelse(bh);
            return result;
            return result;
        }
        }
        brelse(result);
        brelse(result);
        goto repeat;
        goto repeat;
    }
    }
    if (!create) {
    if (!create) {
        brelse(bh);
        brelse(bh);
        return NULL;
        return NULL;
    }
    }
    tmp = xiafs_new_zone(inode->i_sb, prev_addr);
    tmp = xiafs_new_zone(inode->i_sb, prev_addr);
    if (!tmp) {
    if (!tmp) {
        brelse(bh);
        brelse(bh);
        return NULL;
        return NULL;
    }
    }
    result = getblk(bh->b_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
    result = getblk(bh->b_dev, tmp, XIAFS_ZSIZE(inode->i_sb));
    if (*lp) {
    if (*lp) {
        xiafs_free_zone(inode->i_sb, tmp);
        xiafs_free_zone(inode->i_sb, tmp);
        brelse(result);
        brelse(result);
        goto repeat;
        goto repeat;
    }
    }
    *lp = tmp;
    *lp = tmp;
    inode->i_blocks+=2 << XIAFS_ZSHIFT(inode->i_sb);
    inode->i_blocks+=2 << XIAFS_ZSHIFT(inode->i_sb);
    mark_buffer_dirty(bh, 1);
    mark_buffer_dirty(bh, 1);
    brelse(bh);
    brelse(bh);
    return result;
    return result;
}
}
 
 
struct buffer_head * xiafs_getblk(struct inode * inode, int zone, int create)
struct buffer_head * xiafs_getblk(struct inode * inode, int zone, int create)
{
{
    struct buffer_head * bh;
    struct buffer_head * bh;
    u_long prev_addr=0;
    u_long prev_addr=0;
 
 
    if (zone<0) {
    if (zone<0) {
        printk("XIA-FS: zone < 0 (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: zone < 0 (%s %d)\n", WHERE_ERR);
        return NULL;
        return NULL;
    }
    }
    if (zone >= 8+(1+XIAFS_ADDRS_PER_Z(inode->i_sb))*XIAFS_ADDRS_PER_Z(inode->i_sb)) {
    if (zone >= 8+(1+XIAFS_ADDRS_PER_Z(inode->i_sb))*XIAFS_ADDRS_PER_Z(inode->i_sb)) {
        if (!create)
        if (!create)
            printk("XIA-FS: zone > big (%s %d)\n", WHERE_ERR);
            printk("XIA-FS: zone > big (%s %d)\n", WHERE_ERR);
        return NULL;
        return NULL;
    }
    }
    if (create)
    if (create)
        prev_addr=get_prev_addr(inode, zone);
        prev_addr=get_prev_addr(inode, zone);
    if (zone < 8)
    if (zone < 8)
        return dt_getblk(inode, zone+inode->u.xiafs_i.i_zone, create, prev_addr);
        return dt_getblk(inode, zone+inode->u.xiafs_i.i_zone, create, prev_addr);
    zone -= 8;
    zone -= 8;
    if (zone < XIAFS_ADDRS_PER_Z(inode->i_sb)) {
    if (zone < XIAFS_ADDRS_PER_Z(inode->i_sb)) {
        bh = dt_getblk(inode, &(inode->u.xiafs_i.i_ind_zone), create, prev_addr);
        bh = dt_getblk(inode, &(inode->u.xiafs_i.i_ind_zone), create, prev_addr);
        bh = indt_getblk(inode, bh, zone, create, prev_addr);
        bh = indt_getblk(inode, bh, zone, create, prev_addr);
        return bh;
        return bh;
    }
    }
    zone -= XIAFS_ADDRS_PER_Z(inode->i_sb);
    zone -= XIAFS_ADDRS_PER_Z(inode->i_sb);
    bh = dt_getblk(inode, &(inode->u.xiafs_i.i_dind_zone), create, prev_addr);
    bh = dt_getblk(inode, &(inode->u.xiafs_i.i_dind_zone), create, prev_addr);
    bh = indt_getblk(inode, bh, zone>>XIAFS_ADDRS_PER_Z_BITS(inode->i_sb),
    bh = indt_getblk(inode, bh, zone>>XIAFS_ADDRS_PER_Z_BITS(inode->i_sb),
                     create, prev_addr);
                     create, prev_addr);
    bh = indt_getblk(inode, bh, zone&(XIAFS_ADDRS_PER_Z(inode->i_sb)-1),
    bh = indt_getblk(inode, bh, zone&(XIAFS_ADDRS_PER_Z(inode->i_sb)-1),
                     create, prev_addr);
                     create, prev_addr);
    return bh;
    return bh;
}
}
 
 
struct buffer_head * xiafs_bread(struct inode * inode, int zone, int create)
struct buffer_head * xiafs_bread(struct inode * inode, int zone, int create)
{
{
    struct buffer_head * bh;
    struct buffer_head * bh;
 
 
    bh = xiafs_getblk(inode, zone, create);
    bh = xiafs_getblk(inode, zone, create);
    if (!bh || buffer_uptodate(bh))
    if (!bh || buffer_uptodate(bh))
        return bh;
        return bh;
    ll_rw_block(READ, 1, &bh);
    ll_rw_block(READ, 1, &bh);
    wait_on_buffer(bh);
    wait_on_buffer(bh);
    if (buffer_uptodate(bh))
    if (buffer_uptodate(bh))
        return bh;
        return bh;
    brelse(bh);
    brelse(bh);
    return NULL;
    return NULL;
}
}
 
 
void xiafs_read_inode(struct inode * inode)
void xiafs_read_inode(struct inode * inode)
{
{
    struct buffer_head * bh;
    struct buffer_head * bh;
    struct xiafs_inode * raw_inode;
    struct xiafs_inode * raw_inode;
    int zone;
    int zone;
    ino_t ino;
    ino_t ino;
 
 
    ino = inode->i_ino;
    ino = inode->i_ino;
    inode->i_op = NULL;
    inode->i_op = NULL;
    inode->i_mode=0;
    inode->i_mode=0;
    if (!ino || ino > inode->i_sb->u.xiafs_sb.s_ninodes) {
    if (!ino || ino > inode->i_sb->u.xiafs_sb.s_ninodes) {
        printk("XIA-FS: bad inode number (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: bad inode number (%s %d)\n", WHERE_ERR);
        return;
        return;
    }
    }
    zone = 1 + inode->i_sb->u.xiafs_sb.s_imap_zones +
    zone = 1 + inode->i_sb->u.xiafs_sb.s_imap_zones +
                inode->i_sb->u.xiafs_sb.s_zmap_zones +
                inode->i_sb->u.xiafs_sb.s_zmap_zones +
                (ino-1)/ XIAFS_INODES_PER_Z(inode->i_sb);
                (ino-1)/ XIAFS_INODES_PER_Z(inode->i_sb);
    if (!(bh=bread(inode->i_dev, zone, XIAFS_ZSIZE(inode->i_sb)))) {
    if (!(bh=bread(inode->i_dev, zone, XIAFS_ZSIZE(inode->i_sb)))) {
        printk("XIA-FS: read i-node zone failed (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: read i-node zone failed (%s %d)\n", WHERE_ERR);
        return;
        return;
    }
    }
    raw_inode = ((struct xiafs_inode *) bh->b_data) +
    raw_inode = ((struct xiafs_inode *) bh->b_data) +
                 ((ino-1) & (XIAFS_INODES_PER_Z(inode->i_sb) - 1));
                 ((ino-1) & (XIAFS_INODES_PER_Z(inode->i_sb) - 1));
    inode->i_mode = raw_inode->i_mode;
    inode->i_mode = raw_inode->i_mode;
    inode->i_uid = raw_inode->i_uid;
    inode->i_uid = raw_inode->i_uid;
    inode->i_gid = raw_inode->i_gid;
    inode->i_gid = raw_inode->i_gid;
    inode->i_nlink = raw_inode->i_nlinks;
    inode->i_nlink = raw_inode->i_nlinks;
    inode->i_size = raw_inode->i_size;
    inode->i_size = raw_inode->i_size;
    inode->i_mtime = raw_inode->i_mtime;
    inode->i_mtime = raw_inode->i_mtime;
    inode->i_atime = raw_inode->i_atime;
    inode->i_atime = raw_inode->i_atime;
    inode->i_ctime = raw_inode->i_ctime;
    inode->i_ctime = raw_inode->i_ctime;
    inode->i_blksize = XIAFS_ZSIZE(inode->i_sb);
    inode->i_blksize = XIAFS_ZSIZE(inode->i_sb);
    if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
    if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
        inode->i_blocks=0;
        inode->i_blocks=0;
        inode->i_rdev = to_kdev_t(raw_inode->i_zone[0]);
        inode->i_rdev = to_kdev_t(raw_inode->i_zone[0]);
    } else {
    } else {
        XIAFS_GET_BLOCKS(raw_inode, inode->i_blocks);
        XIAFS_GET_BLOCKS(raw_inode, inode->i_blocks);
        for (zone = 0; zone < 8; zone++)
        for (zone = 0; zone < 8; zone++)
            inode->u.xiafs_i.i_zone[zone] = raw_inode->i_zone[zone] & 0xffffff;
            inode->u.xiafs_i.i_zone[zone] = raw_inode->i_zone[zone] & 0xffffff;
        inode->u.xiafs_i.i_ind_zone       = raw_inode->i_ind_zone   & 0xffffff;
        inode->u.xiafs_i.i_ind_zone       = raw_inode->i_ind_zone   & 0xffffff;
        inode->u.xiafs_i.i_dind_zone      = raw_inode->i_dind_zone  & 0xffffff;
        inode->u.xiafs_i.i_dind_zone      = raw_inode->i_dind_zone  & 0xffffff;
    }
    }
    brelse(bh);
    brelse(bh);
    if (S_ISREG(inode->i_mode))
    if (S_ISREG(inode->i_mode))
        inode->i_op = &xiafs_file_inode_operations;
        inode->i_op = &xiafs_file_inode_operations;
    else if (S_ISDIR(inode->i_mode))
    else if (S_ISDIR(inode->i_mode))
        inode->i_op = &xiafs_dir_inode_operations;
        inode->i_op = &xiafs_dir_inode_operations;
    else if (S_ISLNK(inode->i_mode))
    else if (S_ISLNK(inode->i_mode))
        inode->i_op = &xiafs_symlink_inode_operations;
        inode->i_op = &xiafs_symlink_inode_operations;
    else if (S_ISCHR(inode->i_mode))
    else if (S_ISCHR(inode->i_mode))
        inode->i_op = &chrdev_inode_operations;
        inode->i_op = &chrdev_inode_operations;
    else if (S_ISBLK(inode->i_mode))
    else if (S_ISBLK(inode->i_mode))
        inode->i_op = &blkdev_inode_operations;
        inode->i_op = &blkdev_inode_operations;
    else if (S_ISFIFO(inode->i_mode))
    else if (S_ISFIFO(inode->i_mode))
        init_fifo(inode);
        init_fifo(inode);
}
}
 
 
static struct buffer_head *  xiafs_update_inode(struct inode * inode)
static struct buffer_head *  xiafs_update_inode(struct inode * inode)
{
{
    struct buffer_head * bh;
    struct buffer_head * bh;
    struct xiafs_inode * raw_inode;
    struct xiafs_inode * raw_inode;
    int zone;
    int zone;
    ino_t ino;
    ino_t ino;
 
 
    if (IS_RDONLY (inode)) {
    if (IS_RDONLY (inode)) {
        printk("XIA-FS: write_inode on a read-only filesystem (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: write_inode on a read-only filesystem (%s %d)\n", WHERE_ERR);
        inode->i_dirt = 0;
        inode->i_dirt = 0;
        return 0;
        return 0;
    }
    }
 
 
    ino = inode->i_ino;
    ino = inode->i_ino;
    if (!ino || ino > inode->i_sb->u.xiafs_sb.s_ninodes) {
    if (!ino || ino > inode->i_sb->u.xiafs_sb.s_ninodes) {
        printk("XIA-FS: bad inode number (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: bad inode number (%s %d)\n", WHERE_ERR);
        inode->i_dirt=0;
        inode->i_dirt=0;
        return 0;
        return 0;
    }
    }
    zone = 1 + inode->i_sb->u.xiafs_sb.s_imap_zones +
    zone = 1 + inode->i_sb->u.xiafs_sb.s_imap_zones +
                inode->i_sb->u.xiafs_sb.s_zmap_zones +
                inode->i_sb->u.xiafs_sb.s_zmap_zones +
                (ino-1) / XIAFS_INODES_PER_Z(inode->i_sb);
                (ino-1) / XIAFS_INODES_PER_Z(inode->i_sb);
    if (!(bh=bread(inode->i_dev, zone, XIAFS_ZSIZE(inode->i_sb)))) {
    if (!(bh=bread(inode->i_dev, zone, XIAFS_ZSIZE(inode->i_sb)))) {
        printk("XIA-FS: read i-node zone failed (%s %d)\n", WHERE_ERR);
        printk("XIA-FS: read i-node zone failed (%s %d)\n", WHERE_ERR);
        inode->i_dirt=0;
        inode->i_dirt=0;
        return 0;
        return 0;
    }
    }
    raw_inode = ((struct xiafs_inode *)bh->b_data) +
    raw_inode = ((struct xiafs_inode *)bh->b_data) +
                ((ino-1) & (XIAFS_INODES_PER_Z(inode->i_sb) -1));
                ((ino-1) & (XIAFS_INODES_PER_Z(inode->i_sb) -1));
    raw_inode->i_mode = inode->i_mode;
    raw_inode->i_mode = inode->i_mode;
    raw_inode->i_uid = inode->i_uid;
    raw_inode->i_uid = inode->i_uid;
    raw_inode->i_gid = inode->i_gid;
    raw_inode->i_gid = inode->i_gid;
    raw_inode->i_nlinks = inode->i_nlink;
    raw_inode->i_nlinks = inode->i_nlink;
    raw_inode->i_size = inode->i_size;
    raw_inode->i_size = inode->i_size;
    raw_inode->i_atime = inode->i_atime;
    raw_inode->i_atime = inode->i_atime;
    raw_inode->i_ctime = inode->i_ctime;
    raw_inode->i_ctime = inode->i_ctime;
    raw_inode->i_mtime = inode->i_mtime;
    raw_inode->i_mtime = inode->i_mtime;
    if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
    if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
        raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
        raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
    else {
    else {
        XIAFS_PUT_BLOCKS(raw_inode, inode->i_blocks);
        XIAFS_PUT_BLOCKS(raw_inode, inode->i_blocks);
        for (zone = 0; zone < 8; zone++)
        for (zone = 0; zone < 8; zone++)
            raw_inode->i_zone[zone] = (raw_inode->i_zone[zone] & 0xff000000)
            raw_inode->i_zone[zone] = (raw_inode->i_zone[zone] & 0xff000000)
                                     | (inode->u.xiafs_i.i_zone[zone] & 0xffffff);
                                     | (inode->u.xiafs_i.i_zone[zone] & 0xffffff);
        raw_inode->i_ind_zone = (raw_inode->i_ind_zone & 0xff000000)
        raw_inode->i_ind_zone = (raw_inode->i_ind_zone & 0xff000000)
                                     | (inode->u.xiafs_i.i_ind_zone   & 0xffffff);
                                     | (inode->u.xiafs_i.i_ind_zone   & 0xffffff);
        raw_inode->i_dind_zone = (raw_inode->i_dind_zone & 0xff000000)
        raw_inode->i_dind_zone = (raw_inode->i_dind_zone & 0xff000000)
                                     | (inode->u.xiafs_i.i_dind_zone  & 0xffffff);
                                     | (inode->u.xiafs_i.i_dind_zone  & 0xffffff);
    }
    }
    inode->i_dirt=0;
    inode->i_dirt=0;
    mark_buffer_dirty(bh, 1);
    mark_buffer_dirty(bh, 1);
    return bh;
    return bh;
}
}
 
 
 
 
void xiafs_write_inode(struct inode * inode)
void xiafs_write_inode(struct inode * inode)
{
{
    struct buffer_head * bh;
    struct buffer_head * bh;
    bh = xiafs_update_inode(inode);
    bh = xiafs_update_inode(inode);
    brelse (bh);
    brelse (bh);
}
}
 
 
int xiafs_sync_inode (struct inode *inode)
int xiafs_sync_inode (struct inode *inode)
{
{
    int err = 0;
    int err = 0;
    struct buffer_head *bh;
    struct buffer_head *bh;
 
 
    bh = xiafs_update_inode(inode);
    bh = xiafs_update_inode(inode);
    if (bh && buffer_dirty(bh))
    if (bh && buffer_dirty(bh))
    {
    {
        ll_rw_block(WRITE, 1, &bh);
        ll_rw_block(WRITE, 1, &bh);
        wait_on_buffer(bh);
        wait_on_buffer(bh);
        if (buffer_req(bh) && !buffer_uptodate(bh))
        if (buffer_req(bh) && !buffer_uptodate(bh))
        {
        {
            printk ("IO error syncing xiafs inode [%s:%lu]\n",
            printk ("IO error syncing xiafs inode [%s:%lu]\n",
                    kdevname(inode->i_dev), inode->i_ino);
                    kdevname(inode->i_dev), inode->i_ino);
            err = -1;
            err = -1;
        }
        }
    }
    }
    else if (!bh)
    else if (!bh)
        err = -1;
        err = -1;
    brelse (bh);
    brelse (bh);
    return err;
    return err;
}
}
 
 
/* Every kernel module contains stuff like this. */
/* Every kernel module contains stuff like this. */
 
 
static struct file_system_type xiafs_fs_type = {
static struct file_system_type xiafs_fs_type = {
        xiafs_read_super, "xiafs", 1, NULL
        xiafs_read_super, "xiafs", 1, NULL
};
};
 
 
int init_xiafs_fs(void)
int init_xiafs_fs(void)
{
{
        return register_filesystem(&xiafs_fs_type);
        return register_filesystem(&xiafs_fs_type);
}
}
 
 
#ifdef MODULE
#ifdef MODULE
int init_module(void)
int init_module(void)
{
{
        int status;
        int status;
 
 
        if ((status = init_xiafs_fs()) == 0)
        if ((status = init_xiafs_fs()) == 0)
                register_symtab(0);
                register_symtab(0);
        return status;
        return status;
}
}
 
 
void cleanup_module(void)
void cleanup_module(void)
{
{
        unregister_filesystem(&xiafs_fs_type);
        unregister_filesystem(&xiafs_fs_type);
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.