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

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