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

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