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 <asm/segment.h>
  10 
  11 #include <linux/errno.h>
  12 #include <linux/fs.h>
  13 #include <linux/minix_fs.h>
  14 #include <linux/stat.h>
  15 
  16 static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         return -EISDIR;
  19 }
  20 
  21 static int minix_readdir(struct inode *, struct file *, struct dirent *, int);
  22 
  23 static struct file_operations minix_dir_operations = {
  24         NULL,                   /* lseek - default */
  25         minix_dir_read,         /* read */
  26         NULL,                   /* write - bad */
  27         minix_readdir,          /* readdir */
  28         NULL,                   /* select - default */
  29         NULL,                   /* ioctl - default */
  30         NULL,                   /* mmap */
  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 minix_dir_inode_operations = {
  39         &minix_dir_operations,  /* default directory file-ops */
  40         minix_create,           /* create */
  41         minix_lookup,           /* lookup */
  42         minix_link,             /* link */
  43         minix_unlink,           /* unlink */
  44         minix_symlink,          /* symlink */
  45         minix_mkdir,            /* mkdir */
  46         minix_rmdir,            /* rmdir */
  47         minix_mknod,            /* mknod */
  48         minix_rename,           /* rename */
  49         NULL,                   /* readlink */
  50         NULL,                   /* follow_link */
  51         NULL,                   /* bmap */
  52         minix_truncate,         /* truncate */
  53         NULL                    /* permission */
  54 };
  55 
  56 static int minix_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  57         struct dirent * dirent, int count)
  58 {
  59         unsigned int offset,i;
  60         char c;
  61         struct buffer_head * bh;
  62         struct minix_dir_entry * de;
  63 
  64         if (!inode || !S_ISDIR(inode->i_mode))
  65                 return -EBADF;
  66         if (filp->f_pos & (sizeof (struct minix_dir_entry) - 1))
  67                 return -EBADF;
  68         while (filp->f_pos < inode->i_size) {
  69                 offset = filp->f_pos & 1023;
  70                 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  71                 if (!bh) {
  72                         filp->f_pos += 1024-offset;
  73                         continue;
  74                 }
  75                 de = (struct minix_dir_entry *) (offset + bh->b_data);
  76                 while (offset < 1024 && filp->f_pos < inode->i_size) {
  77                         offset += sizeof (struct minix_dir_entry);
  78                         filp->f_pos += sizeof (struct minix_dir_entry);
  79                         if (de->inode) {
  80                                 for (i = 0; i < MINIX_NAME_LEN; i++)
  81                                         if ((c = de->name[i]) != 0)
  82                                                 put_fs_byte(c,i+dirent->d_name);
  83                                         else
  84                                                 break;
  85                                 if (i) {
  86                                         put_fs_long(de->inode,&dirent->d_ino);
  87                                         put_fs_byte(0,i+dirent->d_name);
  88                                         put_fs_word(i,&dirent->d_reclen);
  89                                         brelse(bh);
  90                                         return i;
  91                                 }
  92                         }
  93                         de++;
  94                 }
  95                 brelse(bh);
  96         }
  97         return 0;
  98 }

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