* extfs.c (s_readdir): Simplify.

* direntry.c (vfs_s_readdir): Use vfs_dirent.
* mcfs.c (mcfs_readdir): Likewise.
* smbfs.c (smbfs_readdir): Likewise.
* undelfs.c (undelfs_readdir): Use vfs_dirent and
compute_namelen().
This commit is contained in:
Pavel Roskin 2002-08-15 21:15:17 +00:00
parent 37f335b8c0
commit cf8ab0de99
6 changed files with 65 additions and 94 deletions

View File

@ -1,5 +1,12 @@
2002-08-15 Pavel Roskin <proski@gnu.org>
* extfs.c (s_readdir): Simplify.
* direntry.c (vfs_s_readdir): Use vfs_dirent.
* mcfs.c (mcfs_readdir): Likewise.
* smbfs.c (smbfs_readdir): Likewise.
* undelfs.c (undelfs_readdir): Use vfs_dirent and
compute_namelen().
* vfs.h: Introduce union vfs_dirent to ensure that we have
enough space for the filename.
* extfs.c (s_readdir): Use vfs_dirent. Avoid strcpy().

View File

@ -615,24 +615,20 @@ vfs_s_opendir (vfs *me, char *dirname)
void *
vfs_s_readdir(void *data)
{
static struct {
struct dirent dir;
#ifdef NEED_EXTRA_DIRENT_BUFFER
char extra_buffer [MC_MAXPATHLEN];
#endif
} dir;
static union vfs_dirent dir;
struct dirhandle *info = (struct dirhandle *) data;
if (!(info->cur))
return NULL;
if (info->cur->name)
strcpy (&(dir.dir.d_name [0]), info->cur->name);
else
if (info->cur->name) {
strncpy(dir.dent.d_name, info->cur->name, MC_MAXPATHLEN);
dir.dent.d_name[MC_MAXPATHLEN] = 0;
} else {
vfs_die("Null in structure-can not happen");
}
compute_namelen(&dir.dir);
compute_namelen(&dir.dent);
info->cur = info->cur->next;
return (void *) &dir;

View File

@ -883,17 +883,13 @@ static void * s_opendir (vfs *me, char *dirname)
static void * s_readdir(void *data)
{
static union vfs_dirent dir;
int namelen;
struct entry **info = (struct entry **) data;
if (!*info)
return NULL;
namelen = min (strlen ((*info)->name), MC_MAXPATHLEN);
strncpy (dir.dent.d_name, (*info)->name, namelen);
dir.dent.d_name[namelen] = 0;
strncpy(dir.dent.d_name, (*info)->name, MC_MAXPATHLEN);
dir.dent.d_name[MC_MAXPATHLEN] = 0;
compute_namelen(&dir.dent);
*info = (*info)->next_in_dir;

View File

@ -710,22 +710,13 @@ static void mcfs_free_dir (dir_entry *de)
g_free (de);
}
/* Explanation:
* On some operating systems (Slowaris 2 for example)
* the d_name member is just a char long (Nice trick that break everything,
* so we need to set up some space for the filename.
*/
static struct {
struct dirent dent;
#ifdef NEED_EXTRA_DIRENT_BUFFER
char extra_buffer [MC_MAXPATHLEN];
#endif
} mcfs_readdir_data;
static union vfs_dirent mcfs_readdir_data;
/* The readdir routine loads the complete directory */
/* It's too slow to ask the server each time */
/* It now also sends the complete lstat information for each file */
static struct stat *cached_lstat_info;
static void *mcfs_readdir(void *info)
{
opendir_info *mcfs_info;
@ -743,8 +734,9 @@ static void *mcfs_readdir (void *info)
mcfs_info->entries = 0;
return NULL;
}
dirent_dest = &(mcfs_readdir_data.dent.d_name [0]);
strcpy (dirent_dest, mcfs_info->current->text);
dirent_dest = mcfs_readdir_data.dent.d_name;
strncpy(dirent_dest, mcfs_info->current->text, MC_MAXPATHLEN);
dirent_dest[MC_MAXPATHLEN] = 0;
cached_lstat_info = &mcfs_info->current->my_stat;
mcfs_info->current = mcfs_info->current->next;

View File

@ -720,18 +720,6 @@ smbfs_free_dir (dir_entry *de)
}
#endif
/* Explanation:
* On some operating systems (Slowaris 2 for example)
* the d_name member is just a char long (Nice trick that break everything,
* so we need to set up some space for the filename.
*/
static struct {
struct dirent dent;
#ifdef NEED_EXTRA_DIRENT_BUFFER
char extra_buffer [MC_MAXPATHLEN];
#endif
} smbfs_readdir_data;
/* The readdir routine loads the complete directory */
/* It's too slow to ask the server each time */
@ -739,7 +727,8 @@ static struct {
static void *
smbfs_readdir(void *info)
{
static char * const dirent_dest = &(smbfs_readdir_data.dent.d_name [0]);
static union vfs_dirent smbfs_readdir_data;
static char *const dirent_dest = smbfs_readdir_data.dent.d_name;
opendir_info *smbfs_info = (opendir_info *) info;
DEBUG(4, ("smbfs_readdir(%s)\n", smbfs_info->dirname));
@ -756,7 +745,8 @@ smbfs_readdir (void *info)
#endif
return NULL;
}
pstrcpy (dirent_dest, smbfs_info->current->text);
strncpy(dirent_dest, smbfs_info->current->text, MC_MAXPATHLEN);
dirent_dest[MC_MAXPATHLEN] = 0;
smbfs_info->current = smbfs_info->current->next;
compute_namelen(&smbfs_readdir_data.dent);

View File

@ -319,21 +319,11 @@ quit_opendir:
return 0;
}
/* Explanation:
* On some operating systems (Slowaris 2 for example)
* the d_name member is just a char long (Nice trick that break everything,
* so we need to set up some space for the filename.
*/
static struct {
struct dirent dent;
#ifdef NEED_EXTRA_DIRENT_BUFFER
char extra_buffer [MC_MAXPATHLEN];
#endif
} undelfs_readdir_data;
static void *
undelfs_readdir(void *vfs_info)
{
static union vfs_dirent undelfs_readdir_data;
char *dirent_dest;
if (vfs_info != fs) {
@ -342,18 +332,18 @@ undelfs_readdir (void *vfs_info)
}
if (readdir_ptr == num_delarray)
return NULL;
dirent_dest = (char *) &(undelfs_readdir_data.dent.d_name [0]);
dirent_dest = undelfs_readdir_data.dent.d_name;
if (readdir_ptr < 0)
g_snprintf(dirent_dest, MC_MAXPATHLEN, "%s", readdir_ptr == -2 ? "." : "..");
g_snprintf(dirent_dest, MC_MAXPATHLEN, "%s",
readdir_ptr == -2 ? "." : "..");
else
g_snprintf(dirent_dest, MC_MAXPATHLEN, "%ld:%d",
(long) delarray[readdir_ptr].ino,
delarray[readdir_ptr].num_blocks);
readdir_ptr++;
#if 0
undelfs_readdir_data.dent.d_namlen = strlen (undelfs_readdir_data.dent.d_name);
#endif
compute_namelen(&undelfs_readdir_data.dent);
return &undelfs_readdir_data;
}