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

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