root/fs/xiafs/dir.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. xiafs_dir_read
  2. xiafs_readdir

   1 /*
   2  *  linux/fs/xiafs/dir.c
   3  *  
   4  *  Copyright (C) Q. Frank Xia, 1993.
   5  *  
   6  *  Based on Linus' minix/dir.c
   7  *  Copyright (C) Linus Torvalds, 1991, 1992.
   8  *
   9  *  This software may be redistributed per Linux Copyright.
  10  */
  11 
  12 #include <linux/sched.h>
  13 #include <linux/errno.h>
  14 #include <linux/kernel.h>
  15 #include <linux/fs.h>
  16 #include <linux/xia_fs.h>
  17 #include <linux/stat.h>
  18 
  19 #include <asm/segment.h>
  20 
  21 #include "xiafs_mac.h"
  22 
  23 static int xiafs_dir_read(struct inode *, struct file *, char *, int);
  24 static int xiafs_readdir(struct inode *, struct file *, void *, filldir_t);
  25 
  26 static struct file_operations xiafs_dir_operations = {
  27     NULL,               /* lseek - default */
  28     xiafs_dir_read,     /* read */
  29     NULL,               /* write - bad */
  30     xiafs_readdir,      /* readdir */
  31     NULL,               /* select - default */
  32     NULL,               /* ioctl - default */
  33     NULL,               /* mmap */
  34     NULL,               /* no special open code */
  35     NULL,               /* no special release code */
  36     file_fsync          /* default fsync */
  37 };
  38 
  39 /*
  40  * directories can handle most operations...
  41  */
  42 struct inode_operations xiafs_dir_inode_operations = {
  43     &xiafs_dir_operations,      /* default directory file-ops */
  44     xiafs_create,                       /* create */
  45     xiafs_lookup,                       /* lookup */
  46     xiafs_link,                 /* link */
  47     xiafs_unlink,                       /* unlink */
  48     xiafs_symlink,              /* symlink */
  49     xiafs_mkdir,                        /* mkdir */
  50     xiafs_rmdir,                        /* rmdir */
  51     xiafs_mknod,                        /* mknod */
  52     xiafs_rename,                       /* rename */
  53     NULL,                       /* readlink */
  54     NULL,                       /* follow_link */
  55     NULL,                       /* readpage */
  56     NULL,                       /* writepage */
  57     NULL,                       /* bmap */
  58     xiafs_truncate,             /* truncate */
  59     NULL                        /* permission */
  60 };
  61 
  62 static int xiafs_dir_read(struct inode * inode, 
     /* [previous][next][first][last][top][bottom][index][help] */
  63                         struct file * filp, char * buf, int count)
  64 {
  65   return -EISDIR;
  66 }
  67 
  68 static int xiafs_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  69         void * dirent, filldir_t filldir)
  70 {
  71     u_int offset, i;
  72     struct buffer_head * bh;
  73     struct xiafs_direct * de;
  74 
  75     if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
  76         return -EBADF;
  77     if (inode->i_size & (XIAFS_ZSIZE(inode->i_sb) - 1) )
  78         return -EBADF;
  79     while (filp->f_pos < inode->i_size) {
  80         offset = filp->f_pos & (XIAFS_ZSIZE(inode->i_sb) - 1);
  81         bh = xiafs_bread(inode, filp->f_pos >> XIAFS_ZSIZE_BITS(inode->i_sb),0);
  82         if (!bh) {
  83             filp->f_pos += XIAFS_ZSIZE(inode->i_sb)-offset;
  84             continue;
  85         }
  86         for (i = 0; i < XIAFS_ZSIZE(inode->i_sb) && i < offset; ) {
  87             de = (struct xiafs_direct *) (bh->b_data + i);
  88             if (!de->d_rec_len)
  89                 break;
  90             i += de->d_rec_len;
  91         }
  92         offset = i;
  93         de = (struct xiafs_direct *) (offset + bh->b_data);
  94         
  95         while (offset < XIAFS_ZSIZE(inode->i_sb) && filp->f_pos < inode->i_size) {
  96             if (de->d_ino > inode->i_sb->u.xiafs_sb.s_ninodes ||
  97                 de->d_rec_len < 12 || 
  98                 (char *)de+de->d_rec_len > XIAFS_ZSIZE(inode->i_sb)+bh->b_data ||
  99                 de->d_name_len < 1 || de->d_name_len + 8 > de->d_rec_len ||
 100                 de->d_name_len > _XIAFS_NAME_LEN ||
 101                 de->d_name[de->d_name_len] ) {
 102                 printk("XIA-FS: bad directory entry (%s %d)\n", WHERE_ERR);
 103                 brelse(bh);
 104                 return 0;
 105             }  
 106             if (de->d_ino) {
 107                 if (!IS_RDONLY (inode)) {
 108                     inode->i_atime=CURRENT_TIME;
 109                     inode->i_dirt=1;
 110                 }
 111                 if (filldir(dirent, de->d_name, de->d_name_len, filp->f_pos, de->d_ino) < 0) {
 112                     brelse(bh);
 113                     return 0;
 114                 }
 115             }
 116             offset += de->d_rec_len;
 117             filp->f_pos += de->d_rec_len;
 118             de = (struct xiafs_direct *) (offset + bh->b_data);
 119         }
 120         brelse(bh);
 121         if (offset > XIAFS_ZSIZE(inode->i_sb)) {
 122             printk("XIA-FS: bad directory (%s %d)\n", WHERE_ERR);
 123             return 0;
 124         }
 125     }
 126     if (!IS_RDONLY (inode)) {
 127         inode->i_atime=CURRENT_TIME;                
 128         inode->i_dirt=1;
 129     }
 130     return 0;
 131 }

/* [previous][next][first][last][top][bottom][index][help] */