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         NULL,                   /* readpage */
  55         NULL,                   /* writepage */
  56         msdos_bmap,             /* bmap */
  57         NULL,                   /* truncate */
  58         NULL                    /* permission */
  59 };
  60 
  61 int msdos_readdir(
     /* [previous][next][first][last][top][bottom][index][help] */
  62         struct inode *inode,
  63         struct file *filp,
  64         void *dirent,
  65         filldir_t filldir)
  66 {
  67         struct super_block *sb = inode->i_sb;
  68         int ino,i,i2,last;
  69         char c;
  70         struct buffer_head *bh;
  71         struct msdos_dir_entry *de;
  72         unsigned long oldpos = filp->f_pos;
  73 
  74         if (!inode || !S_ISDIR(inode->i_mode))
  75                 return -EBADF;
  76 /* Fake . and .. for the root directory. */
  77         if (inode->i_ino == MSDOS_ROOT_INO) {
  78                 while (oldpos < 2) {
  79                         if (filldir(dirent, "..", oldpos+1, oldpos, MSDOS_ROOT_INO) < 0)
  80                                 return 0;
  81                         oldpos++;
  82                         filp->f_pos++;
  83                 }
  84                 if (oldpos == 2)
  85                         filp->f_pos = 0;
  86         }
  87         if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1))
  88                 return -ENOENT;
  89         bh = NULL;
  90         while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
  91                 if (!IS_FREE(de->name) && !(de->attr & ATTR_VOLUME)) {
  92                         char bufname[13];
  93                         char *ptname = bufname;
  94                         int dotoffset = 0;
  95                         if ((de->attr & ATTR_HIDDEN) && MSDOS_SB(sb)->dotsOK) {
  96                                 bufname[0] = '.';
  97                                 dotoffset = 1;
  98                                 ptname = bufname+1;
  99                         }
 100                         for (i = last = 0; i < 8; i++) {
 101                                 if (!(c = de->name[i])) break;
 102                                 if (c >= 'A' && c <= 'Z') c += 32;
 103                                 /* see namei.c, msdos_format_name */
 104                                 if (c == 0x05) c = 0xE5;
 105                                 if (c != ' ')
 106                                         last = i+1;
 107                                 ptname[i] = c;
 108                         }
 109                         i = last;
 110                         ptname[i] = '.';
 111                         i++;
 112                         for (i2 = 0; i2 < 3; i2++) {
 113                                 if (!(c = de->ext[i2])) break;
 114                                 if (c >= 'A' && c <= 'Z') c += 32;
 115                                 if (c != ' ')
 116                                         last = i+1;
 117                                 ptname[i] = c;
 118                                 i++;
 119                         }
 120                         if ((i = last) != 0) {
 121                                 if (!strcmp(de->name,MSDOS_DOT))
 122                                         ino = inode->i_ino;
 123                                 else if (!strcmp(de->name,MSDOS_DOTDOT))
 124                                         ino = msdos_parent_ino(inode,0);
 125                                 if (filldir(dirent, bufname, i+dotoffset, oldpos, ino) < 0) {
 126                                         filp->f_pos = oldpos;
 127                                         break;
 128                                 }
 129                         }
 130                 }
 131                 oldpos = filp->f_pos;
 132         }
 133         if (bh) brelse(bh);
 134         return 0;
 135 }

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