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 *, struct dirent *, int);
  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 };
  41 
  42 /*
  43  * directories can handle most operations...
  44  */
  45 struct inode_operations ext_dir_inode_operations = {
  46         &ext_dir_operations,    /* default directory file-ops */
  47         ext_create,             /* create */
  48         ext_lookup,             /* lookup */
  49         ext_link,               /* link */
  50         ext_unlink,             /* unlink */
  51         ext_symlink,            /* symlink */
  52         ext_mkdir,              /* mkdir */
  53         ext_rmdir,              /* rmdir */
  54         ext_mknod,              /* mknod */
  55         ext_rename,             /* rename */
  56         NULL,                   /* readlink */
  57         NULL,                   /* follow_link */
  58         NULL,                   /* bmap */
  59         ext_truncate            /* truncate */
  60 };
  61 
  62 static int ext_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  63         struct dirent * dirent, int count)
  64 {
  65         unsigned int offset,i;
  66         char c;
  67         struct buffer_head * bh;
  68         struct ext_dir_entry * de;
  69 
  70         if (!inode || !S_ISDIR(inode->i_mode))
  71                 return -EBADF;
  72         if (filp->f_pos % 8 != 0)
  73                 return -EBADF;
  74         while (filp->f_pos < inode->i_size) {
  75                 offset = filp->f_pos & 1023;
  76                 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  77                 if (!bh) {
  78                         filp->f_pos += 1024-offset;
  79                         continue;
  80                 }
  81                 de = (struct ext_dir_entry *) (offset + bh->b_data);
  82                 while (offset < 1024 && filp->f_pos < inode->i_size) {
  83                         if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
  84                             de->rec_len < de->name_len + 8 ||
  85                             (de->rec_len + filp->f_pos - 1) / 1024 > (filp->f_pos / 1024)) {
  86                                 printk ("ext_readdir: bad dir entry, skipping\n");
  87                                 printk ("dev=%d, dir=%d, offset=%d, rec_len=%d, name_len=%d\n",
  88                                         inode->i_dev, inode->i_ino, offset, de->rec_len, de->name_len);
  89                                 filp->f_pos += 1024-offset;
  90                                 if (filp->f_pos > inode->i_size)
  91                                         filp->f_pos = inode->i_size;
  92                                 continue;
  93                         }
  94                         offset += de->rec_len;
  95                         filp->f_pos += de->rec_len;
  96                         if (de->inode) {
  97                                 for (i = 0; i < de->name_len; i++)
  98                                         if ((c = de->name[i]) != 0)
  99                                                 put_fs_byte(c,i+dirent->d_name);
 100                                         else
 101                                                 break;
 102                                 if (i) {
 103                                         put_fs_long(de->inode,&dirent->d_ino);
 104                                         put_fs_byte(0,i+dirent->d_name);
 105                                         put_fs_word(i,&dirent->d_reclen);
 106                                         brelse(bh);
 107                                         return i;
 108                                 }
 109                         }
 110                         de = (struct ext_dir_entry *) ((char *) de 
 111                                 + de->rec_len);
 112                 }
 113                 brelse(bh);
 114         }
 115         return 0;
 116 }

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