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

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