root/fs/minix/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. minix_dir_read
  2. minix_readdir

   1 /*
   2  *  linux/fs/minix/dir.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  minix directory handling functions
   7  */
   8 
   9 #ifdef MODULE
  10 #include <linux/module.h>
  11 #endif
  12 
  13 #include <linux/string.h>
  14 #include <linux/errno.h>
  15 #include <linux/fs.h>
  16 #include <linux/minix_fs.h>
  17 #include <linux/stat.h>
  18 
  19 #include <asm/segment.h>
  20 
  21 static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23         return -EISDIR;
  24 }
  25 
  26 static int minix_readdir(struct inode *, struct file *, void *, filldir_t);
  27 
  28 static struct file_operations minix_dir_operations = {
  29         NULL,                   /* lseek - default */
  30         minix_dir_read,         /* read */
  31         NULL,                   /* write - bad */
  32         minix_readdir,          /* readdir */
  33         NULL,                   /* select - default */
  34         NULL,                   /* ioctl - default */
  35         NULL,                   /* mmap */
  36         NULL,                   /* no special open code */
  37         NULL,                   /* no special release code */
  38         file_fsync              /* default fsync */
  39 };
  40 
  41 /*
  42  * directories can handle most operations...
  43  */
  44 struct inode_operations minix_dir_inode_operations = {
  45         &minix_dir_operations,  /* default directory file-ops */
  46         minix_create,           /* create */
  47         minix_lookup,           /* lookup */
  48         minix_link,             /* link */
  49         minix_unlink,           /* unlink */
  50         minix_symlink,          /* symlink */
  51         minix_mkdir,            /* mkdir */
  52         minix_rmdir,            /* rmdir */
  53         minix_mknod,            /* mknod */
  54         minix_rename,           /* rename */
  55         NULL,                   /* readlink */
  56         NULL,                   /* follow_link */
  57         NULL,                   /* bmap */
  58         minix_truncate,         /* truncate */
  59         NULL                    /* permission */
  60 };
  61 
  62 static int minix_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  63         void * dirent, filldir_t filldir)
  64 {
  65         unsigned int offset;
  66         struct buffer_head * bh;
  67         struct minix_dir_entry * de;
  68         struct minix_sb_info * info;
  69 
  70         if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
  71                 return -EBADF;
  72         info = &inode->i_sb->u.minix_sb;
  73         if (filp->f_pos & (info->s_dirsize - 1))
  74                 return -EBADF;
  75         while (filp->f_pos < inode->i_size) {
  76                 offset = filp->f_pos & 1023;
  77                 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  78                 if (!bh) {
  79                         filp->f_pos += 1024-offset;
  80                         continue;
  81                 }
  82                 do {
  83                         de = (struct minix_dir_entry *) (offset + bh->b_data);
  84                         if (de->inode) {
  85                                 int size = strnlen(de->name, info->s_namelen);
  86                                 if (filldir(dirent, de->name, size, filp->f_pos, de->inode) < 0) {
  87                                         brelse(bh);
  88                                         return 0;
  89                                 }
  90                         }
  91                         offset += info->s_dirsize;
  92                         filp->f_pos += info->s_dirsize;
  93                 } while (offset < 1024 && filp->f_pos < inode->i_size);
  94                 brelse(bh);
  95         }
  96         return 0;
  97 }

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