root/fs/sysv/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. sysv_dir_read
  2. sysv_readdir

   1 /*
   2  *  linux/fs/sysv/dir.c
   3  *
   4  *  minix/dir.c
   5  *  Copyright (C) 1991, 1992  Linus Torvalds
   6  *
   7  *  coh/dir.c
   8  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
   9  *
  10  *  sysv/dir.c
  11  *  Copyright (C) 1993  Bruno Haible
  12  *
  13  *  SystemV/Coherent directory handling functions
  14  */
  15 
  16 #include <linux/errno.h>
  17 #include <linux/fs.h>
  18 #include <linux/sysv_fs.h>
  19 #include <linux/stat.h>
  20 #include <linux/string.h>
  21 
  22 #include <asm/segment.h>
  23 
  24 static int sysv_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         return -EISDIR;
  27 }
  28 
  29 static int sysv_readdir(struct inode *, struct file *, void *, filldir_t);
  30 
  31 static struct file_operations sysv_dir_operations = {
  32         NULL,                   /* lseek - default */
  33         sysv_dir_read,          /* read */
  34         NULL,                   /* write - bad */
  35         sysv_readdir,           /* readdir */
  36         NULL,                   /* select - default */
  37         NULL,                   /* ioctl - default */
  38         NULL,                   /* mmap */
  39         NULL,                   /* no special open code */
  40         NULL,                   /* no special release code */
  41         file_fsync              /* default fsync */
  42 };
  43 
  44 /*
  45  * directories can handle most operations...
  46  */
  47 struct inode_operations sysv_dir_inode_operations = {
  48         &sysv_dir_operations,   /* default directory file-ops */
  49         sysv_create,            /* create */
  50         sysv_lookup,            /* lookup */
  51         sysv_link,              /* link */
  52         sysv_unlink,            /* unlink */
  53         sysv_symlink,           /* symlink */
  54         sysv_mkdir,             /* mkdir */
  55         sysv_rmdir,             /* rmdir */
  56         sysv_mknod,             /* mknod */
  57         sysv_rename,            /* rename */
  58         NULL,                   /* readlink */
  59         NULL,                   /* follow_link */
  60         NULL,                   /* bmap */
  61         sysv_truncate,          /* truncate */
  62         NULL                    /* permission */
  63 };
  64 
  65 static int sysv_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  66         void * dirent, filldir_t filldir)
  67 {
  68         struct super_block * sb;
  69         unsigned int offset,i;
  70         struct buffer_head * bh;
  71         char* bh_data;
  72         struct sysv_dir_entry * de, sde;
  73 
  74         if (!inode || !(sb = inode->i_sb) || !S_ISDIR(inode->i_mode))
  75                 return -EBADF;
  76         if ((unsigned long)(filp->f_pos) % SYSV_DIRSIZE)
  77                 return -EBADF;
  78         while (filp->f_pos < inode->i_size) {
  79                 offset = filp->f_pos & sb->sv_block_size_1;
  80                 bh = sysv_file_bread(inode, filp->f_pos >> sb->sv_block_size_bits, 0);
  81                 if (!bh) {
  82                         filp->f_pos += sb->sv_block_size - offset;
  83                         continue;
  84                 }
  85                 bh_data = bh->b_data;
  86                 while (offset < sb->sv_block_size && filp->f_pos < inode->i_size) {
  87                         de = (struct sysv_dir_entry *) (offset + bh_data);
  88                         if (de->inode) {
  89                                 /* Copy the directory entry first, because the directory
  90                                  * might be modified while we sleep in filldir()...
  91                                  */
  92                                 memcpy(&sde, de, sizeof(struct sysv_dir_entry));
  93 
  94                                 if (sde.inode > inode->i_sb->sv_ninodes)
  95                                         printk("sysv_readdir: Bad inode number on dev "
  96                                                "%s, ino %ld, offset 0x%04lx: %d is out of range\n",
  97                                                kdevname(inode->i_dev),
  98                                                inode->i_ino, (off_t) filp->f_pos, sde.inode);
  99 
 100                                 i = strnlen(sde.name, SYSV_NAMELEN);
 101                                 if (filldir(dirent, sde.name, i, filp->f_pos, sde.inode) < 0) {
 102                                         brelse(bh);
 103                                         return 0;
 104                                 }
 105                         }
 106                         offset += SYSV_DIRSIZE;
 107                         filp->f_pos += SYSV_DIRSIZE;
 108                 }
 109                 brelse(bh);
 110         }
 111         return 0;
 112 }

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