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 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
  23 #define ROUND_UP(x) (((x)+3) & ~3)
  24 
  25 static int xiafs_dir_read(struct inode *, struct file *, char *, int);
  26 static int xiafs_readdir(struct inode *, struct file *, struct dirent *, int);
  27 
  28 static struct file_operations xiafs_dir_operations = {
  29     NULL,               /* lseek - default */
  30     xiafs_dir_read,     /* read */
  31     NULL,               /* write - bad */
  32     xiafs_readdir,      /* readdir */
  33     NULL,               /* select - default */
  34     NULL,               /* ioctl - default */
  35     NULL,               /* mmap */
  36     NULL,               /* no special open code */
  37     NULL,               /* no special release code */
  38     file_fsync          /* default fsync */
  39 };
  40 
  41 /*
  42  * directories can handle most operations...
  43  */
  44 struct inode_operations xiafs_dir_inode_operations = {
  45     &xiafs_dir_operations,      /* default directory file-ops */
  46     xiafs_create,                       /* create */
  47     xiafs_lookup,                       /* lookup */
  48     xiafs_link,                 /* link */
  49     xiafs_unlink,                       /* unlink */
  50     xiafs_symlink,              /* symlink */
  51     xiafs_mkdir,                        /* mkdir */
  52     xiafs_rmdir,                        /* rmdir */
  53     xiafs_mknod,                        /* mknod */
  54     xiafs_rename,                       /* rename */
  55     NULL,                       /* readlink */
  56     NULL,                       /* follow_link */
  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, 
     /* [previous][next][first][last][top][bottom][index][help] */
  69                        struct file * filp, struct dirent * dirent, int count)
  70 {
  71     u_int offset, i,ret;
  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     ret = 0;
  80     while (!ret && 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 (!ret && 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             offset += de->d_rec_len;
 108             filp->f_pos += de->d_rec_len;
 109             if (de->d_ino) {
 110                 for (i = 0; i < de->d_name_len ; i++)
 111                     put_fs_byte(de->d_name[i],i+dirent->d_name);
 112                 put_fs_byte(0,i+dirent->d_name);
 113                 put_fs_long(de->d_ino,&dirent->d_ino);
 114                 put_fs_word(i,&dirent->d_reclen);
 115                 if (!IS_RDONLY (inode)) {
 116                     inode->i_atime=CURRENT_TIME;                    
 117                     inode->i_dirt=1;
 118                 }
 119                 ret = ROUND_UP(NAME_OFFSET(dirent)+i+1);
 120                 break;
 121             }
 122             de = (struct xiafs_direct *) (offset + bh->b_data);
 123         }
 124         brelse(bh);
 125         if (offset > XIAFS_ZSIZE(inode->i_sb)) {
 126             printk("XIA-FS: bad directory (%s %d)\n", WHERE_ERR);
 127             return 0;
 128         }
 129     }
 130     if (!IS_RDONLY (inode)) {
 131         inode->i_atime=CURRENT_TIME;                
 132         inode->i_dirt=1;
 133     }
 134     return ret;
 135 }

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