root/fs/minix/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. 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_readdir(struct inode *, struct file *, struct dirent *, int);
  17 
  18 static struct file_operations minix_dir_operations = {
  19         NULL,                   /* lseek - default */
  20         minix_file_read,        /* read */
  21         NULL,                   /* write - bad */
  22         minix_readdir,          /* readdir */
  23         NULL,                   /* select - default */
  24         NULL,                   /* ioctl - default */
  25         NULL,                   /* no special open code */
  26         NULL                    /* no special release code */
  27 };
  28 
  29 /*
  30  * directories can handle most operations...
  31  */
  32 struct inode_operations minix_dir_inode_operations = {
  33         &minix_dir_operations,  /* default directory file-ops */
  34         minix_create,           /* create */
  35         minix_lookup,           /* lookup */
  36         minix_link,             /* link */
  37         minix_unlink,           /* unlink */
  38         minix_symlink,          /* symlink */
  39         minix_mkdir,            /* mkdir */
  40         minix_rmdir,            /* rmdir */
  41         minix_mknod,            /* mknod */
  42         minix_rename,           /* rename */
  43         NULL,                   /* readlink */
  44         NULL,                   /* follow_link */
  45         NULL,                   /* bmap */
  46         minix_truncate          /* truncate */
  47 };
  48 
  49 static int minix_readdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
  50         struct dirent * dirent, int count)
  51 {
  52         unsigned int offset,i;
  53         char c;
  54         struct buffer_head * bh;
  55         struct minix_dir_entry * de;
  56 
  57         if (!inode || !S_ISDIR(inode->i_mode))
  58                 return -EBADF;
  59         if (filp->f_pos & (sizeof (struct minix_dir_entry) - 1))
  60                 return -EBADF;
  61         while (filp->f_pos < inode->i_size) {
  62                 offset = filp->f_pos & 1023;
  63                 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
  64                 if (!bh) {
  65                         filp->f_pos += 1024-offset;
  66                         continue;
  67                 }
  68                 de = (struct minix_dir_entry *) (offset + bh->b_data);
  69                 while (offset < 1024 && filp->f_pos < inode->i_size) {
  70                         offset += sizeof (struct minix_dir_entry);
  71                         filp->f_pos += sizeof (struct minix_dir_entry);
  72                         if (de->inode) {
  73                                 for (i = 0; i < MINIX_NAME_LEN; i++)
  74                                         if (c = de->name[i])
  75                                                 put_fs_byte(c,i+dirent->d_name);
  76                                         else
  77                                                 break;
  78                                 if (i) {
  79                                         put_fs_long(de->inode,&dirent->d_ino);
  80                                         put_fs_byte(0,i+dirent->d_name);
  81                                         put_fs_word(i,&dirent->d_reclen);
  82                                         brelse(bh);
  83                                         return i;
  84                                 }
  85                         }
  86                         de++;
  87                 }
  88                 brelse(bh);
  89         }
  90         return 0;
  91 }

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