root/fs/ext/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. ext_dir_read
  2. ext_readdir

   1 /*
   2  *  linux/fs/ext/dir.c
   3  *
   4  *  Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
   5  *
   6  *  from
   7  *
   8  *  linux/fs/minix/dir.c
   9  *
  10  *  Copyright (C) 1991, 1992 Linus Torvalds
  11  *
  12  *  ext directory handling functions
  13  */
  14 
  15 #include <asm/segment.h>
  16 
  17 #include <linux/errno.h>
  18 #include <linux/kernel.h>
  19 #include <linux/fs.h>
  20 #include <linux/ext_fs.h>
  21 #include <linux/stat.h>
  22 
  23 static int ext_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         return -EISDIR;
  26 }
  27 
  28 static int ext_readdir(struct inode *, struct file *, void *, filldir_t);
  29 
  30 static struct file_operations ext_dir_operations = {
  31         NULL,                   /* lseek - default */
  32         ext_dir_read,           /* read */
  33         NULL,                   /* write - bad */
  34         ext_readdir,            /* readdir */
  35         NULL,                   /* select - default */
  36         NULL,                   /* ioctl - default */
  37         NULL,                   /* mmap */
  38         NULL,                   /* no special open code */
  39         NULL,                   /* no special release code */
  40         file_fsync              /* fsync */
  41 };
  42 
  43 /*
  44  * directories can handle most operations...
  45  */
  46 struct inode_operations ext_dir_inode_operations = {
  47         &ext_dir_operations,    /* default directory file-ops */
  48         ext_create,             /* create */
  49         ext_lookup,             /* lookup */
  50         ext_link,               /* link */
  51         ext_unlink,             /* unlink */
  52         ext_symlink,            /* symlink */
  53         ext_mkdir,              /* mkdir */
  54         ext_rmdir,              /* rmdir */
  55         ext_mknod,              /* mknod */
  56         ext_rename,             /* rename */
  57         NULL,                   /* readlink */
  58         NULL,                   /* follow_link */
  59         NULL,                   /* bmap */
  60         ext_truncate,           /* truncate */
  61         NULL                    /* permission */
  62 };
  63 
  64 static int ext_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  65         void * dirent, filldir_t filldir)
  66 {
  67         int error;
  68         unsigned int i;
  69         off_t offset;
  70         struct buffer_head * bh;
  71         struct ext_dir_entry * de;
  72 
  73         if (!inode || !S_ISDIR(inode->i_mode))
  74                 return -EBADF;
  75         if ((filp->f_pos & 7) != 0)
  76                 return -EBADF;
  77         error = 0;
  78         while (!error && filp->f_pos < inode->i_size) {
  79                 offset = filp->f_pos & 1023;
  80                 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  81                 if (!bh) {
  82                         filp->f_pos += 1024-offset;
  83                         continue;
  84                 }
  85                 for (i = 0; i < 1024 && i < offset; ) {
  86                         de = (struct ext_dir_entry *) (bh->b_data + i);
  87                         if (!de->rec_len)
  88                                 break;
  89                         i += de->rec_len;
  90                 }
  91                 offset = i;
  92                 de = (struct ext_dir_entry *) (offset + bh->b_data);
  93                 while (offset < 1024 && filp->f_pos < inode->i_size) {
  94                         if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
  95                             de->rec_len < de->name_len + 8 ||
  96                             (de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
  97                                 printk ("ext_readdir: bad dir entry, skipping\n");
  98                                 printk ("dev=%d, dir=%ld, offset=%ld, rec_len=%d, name_len=%d\n",
  99                                         inode->i_dev, inode->i_ino, offset, de->rec_len, de->name_len);
 100                                 filp->f_pos += 1024-offset;
 101                                 if (filp->f_pos > inode->i_size)
 102                                         filp->f_pos = inode->i_size;
 103                                 continue;
 104                         }
 105                         if (de->inode) {
 106                                 error = filldir(dirent, de->name, de->name_len, filp->f_pos, de->inode);
 107                                 if (error)
 108                                         break;
 109                         }
 110                         offset += de->rec_len;
 111                         filp->f_pos += de->rec_len;
 112                         ((char *) de) += de->rec_len;
 113                 }
 114                 brelse(bh);
 115         }
 116         return 0;
 117 }

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