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

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