root/fs/msdos/dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. msdos_dir_read
  2. msdos_readdir

   1 /*
   2  *  linux/fs/msdos/dir.c
   3  *
   4  *  Written 1992,1993 by Werner Almesberger
   5  *
   6  *  MS-DOS directory handling functions
   7  */
   8 
   9 #include <linux/fs.h>
  10 #include <linux/msdos_fs.h>
  11 #include <linux/errno.h>
  12 #include <linux/stat.h>
  13 #include <linux/string.h>
  14 
  15 #include <asm/segment.h>
  16 
  17 #include "msbuffer.h"
  18 
  19 
  20 #define PRINTK(X)
  21 
  22 static int msdos_dir_read(struct inode * inode,struct file * filp, char * buf,int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  23 {
  24         return -EISDIR;
  25 }
  26 
  27 static struct file_operations msdos_dir_operations = {
  28         NULL,                   /* lseek - default */
  29         msdos_dir_read,         /* read */
  30         NULL,                   /* write - bad */
  31         msdos_readdir,          /* readdir */
  32         NULL,                   /* select - default */
  33         NULL,                   /* ioctl - default */
  34         NULL,                   /* mmap */
  35         NULL,                   /* no special open code */
  36         NULL,                   /* no special release code */
  37         file_fsync              /* fsync */
  38 };
  39 
  40 struct inode_operations msdos_dir_inode_operations = {
  41         &msdos_dir_operations,  /* default directory file-ops */
  42         msdos_create,           /* create */
  43         msdos_lookup,           /* lookup */
  44         NULL,                   /* link */
  45         msdos_unlink,           /* unlink */
  46         NULL,                   /* symlink */
  47         msdos_mkdir,            /* mkdir */
  48         msdos_rmdir,            /* rmdir */
  49         NULL,                   /* mknod */
  50         msdos_rename,           /* rename */
  51         NULL,                   /* readlink */
  52         NULL,                   /* follow_link */
  53         msdos_bmap,             /* bmap */
  54         NULL,                   /* truncate */
  55         NULL                    /* permission */
  56 };
  57 
  58 int msdos_readdir(
     /* [previous][next][first][last][top][bottom][index][help] */
  59         struct inode *inode,
  60         struct file *filp,
  61         void *dirent,
  62         filldir_t filldir)
  63 {
  64         struct super_block *sb = inode->i_sb;
  65         int ino,i,i2,last;
  66         char c;
  67         struct buffer_head *bh;
  68         struct msdos_dir_entry *de;
  69         unsigned long oldpos = filp->f_pos;
  70 
  71         if (!inode || !S_ISDIR(inode->i_mode))
  72                 return -EBADF;
  73 /* Fake . and .. for the root directory. */
  74         if (inode->i_ino == MSDOS_ROOT_INO) {
  75                 while (oldpos < 2) {
  76                         if (filldir(dirent, "..", oldpos+1, oldpos, MSDOS_ROOT_INO) < 0)
  77                                 return 0;
  78                         oldpos++;
  79                         filp->f_pos++;
  80                 }
  81                 if (oldpos == 2)
  82                         filp->f_pos = 0;
  83         }
  84         if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1))
  85                 return -ENOENT;
  86         bh = NULL;
  87         while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
  88                 if (!IS_FREE(de->name)
  89                         && !(de->attr & (ATTR_VOLUME|ATTR_SYS|ATTR_HIDDEN))) {
  90                         char bufname[12];
  91                         char *ptname = bufname;
  92                         for (i = last = 0; i < 8; i++) {
  93                                 if (!(c = de->name[i])) break;
  94                                 if (c >= 'A' && c <= 'Z') c += 32;
  95                                 if (c != ' ')
  96                                         last = i+1;
  97                                 ptname[i] = c;
  98                         }
  99                         i = last;
 100                         ptname[i] = '.';
 101                         i++;
 102                         for (i2 = 0; i2 < 3; i2++) {
 103                                 if (!(c = de->ext[i2])) break;
 104                                 if (c >= 'A' && c <= 'Z') c += 32;
 105                                 if (c != ' ')
 106                                         last = i+1;
 107                                 ptname[i] = c;
 108                                 i++;
 109                         }
 110                         if ((i = last) != 0) {
 111                                 if (!strcmp(de->name,MSDOS_DOT))
 112                                         ino = inode->i_ino;
 113                                 else if (!strcmp(de->name,MSDOS_DOTDOT))
 114                                         ino = msdos_parent_ino(inode,0);
 115                                 if (filldir(dirent, bufname, i, oldpos, ino) < 0) {
 116                                         filp->f_pos = oldpos;
 117                                         break;
 118                                 }
 119                         }
 120                 }
 121                 oldpos = filp->f_pos;
 122         }
 123         if (bh) brelse(bh);
 124         return 0;
 125 }

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