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

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