root/fs/ext/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. 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/fs.h>
  19 #include <linux/ext_fs.h>
  20 #include <linux/stat.h>
  21 
  22 static int ext_readdir(struct inode *, struct file *, struct dirent *, int);
  23 
  24 static struct file_operations ext_dir_operations = {
  25         NULL,                   /* lseek - default */
  26         NULL,                   /* read */
  27         NULL,                   /* write - bad */
  28         ext_readdir,            /* readdir */
  29         NULL,                   /* select - default */
  30         NULL,                   /* ioctl - default */
  31         NULL,                   /* no special open code */
  32         NULL                    /* no special release code */
  33 };
  34 
  35 /*
  36  * directories can handle most operations...
  37  */
  38 struct inode_operations ext_dir_inode_operations = {
  39         &ext_dir_operations,    /* default directory file-ops */
  40         ext_create,             /* create */
  41         ext_lookup,             /* lookup */
  42         ext_link,               /* link */
  43         ext_unlink,             /* unlink */
  44         ext_symlink,            /* symlink */
  45         ext_mkdir,              /* mkdir */
  46         ext_rmdir,              /* rmdir */
  47         ext_mknod,              /* mknod */
  48         ext_rename,             /* rename */
  49         NULL,                   /* readlink */
  50         NULL,                   /* follow_link */
  51         NULL,                   /* bmap */
  52         ext_truncate            /* truncate */
  53 };
  54 
  55 static int ext_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  56         struct dirent * dirent, int count)
  57 {
  58         unsigned int offset,i;
  59         char c;
  60         struct buffer_head * bh;
  61         struct ext_dir_entry * de;
  62 
  63         if (!inode || !S_ISDIR(inode->i_mode))
  64                 return -EBADF;
  65         while (filp->f_pos < inode->i_size) {
  66                 offset = filp->f_pos & 1023;
  67                 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  68                 if (!bh) {
  69                         filp->f_pos += 1024-offset;
  70                         continue;
  71                 }
  72                 de = (struct ext_dir_entry *) (offset + bh->b_data);
  73                 while (offset < 1024 && filp->f_pos < inode->i_size) {
  74                         offset += de->rec_len;
  75                         filp->f_pos += de->rec_len;
  76                         if (de->inode) {
  77                                 for (i = 0; i < de->name_len; i++)
  78                                         if (c = de->name[i])
  79                                                 put_fs_byte(c,i+dirent->d_name);
  80                                         else
  81                                                 break;
  82                                 if (i) {
  83                                         put_fs_long(de->inode,&dirent->d_ino);
  84                                         put_fs_byte(0,i+dirent->d_name);
  85                                         put_fs_word(i,&dirent->d_reclen);
  86                                         brelse(bh);
  87                                         return i;
  88                                 }
  89                         }
  90                         de = (struct ext_dir_entry *) ((char *) de 
  91                                 + de->rec_len);
  92                 }
  93                 brelse(bh);
  94         }
  95         return 0;
  96 }

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