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

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