From 14c3f90d2f34e3b010c15763d611871e94dd1514 Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Thu, 12 Sep 2002 06:25:21 +0000 Subject: [PATCH] * smbfs.c (statfile_helper): Merge with loaddir_helper(). (get_remote_stat): Use loaddir_helper(). Care about single_entry instead of eliminated statfile_helper(). --- vfs/ChangeLog | 4 +++ vfs/smbfs.c | 87 +++++++++++++++++---------------------------------- 2 files changed, 33 insertions(+), 58 deletions(-) diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 706502207..dfbc1b2b8 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,5 +1,9 @@ 2002-09-11 Andrew V. Samoilov + * smbfs.c (statfile_helper): Merge with loaddir_helper(). + (get_remote_stat): Use loaddir_helper(). Care about + single_entry instead of eliminated statfile_helper(). + * samba/libsmb/clientgen.c (cli_NetServerEnum): Add void* parameter to (*fn)() and void *state parameter. (cli_list): Likewise. diff --git a/vfs/smbfs.c b/vfs/smbfs.c index 47665e151..f244a96ef 100644 --- a/vfs/smbfs.c +++ b/vfs/smbfs.c @@ -454,13 +454,14 @@ browsing_helper (const char *name, uint32 type, const char *comment, void *state static void loaddir_helper (file_info * finfo, const char *mask, void *entry) { - dir_entry *new_entry; + dir_entry *new_entry = (dir_entry *) entry; time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */ #if 0 /* I want to see dot files */ if (finfo->mode & aHIDDEN) return; /* don't bother with hidden files, "~$" screws up mc */ #endif - new_entry = new_dir_entry (finfo->name); + if (!entry) + new_entry = new_dir_entry (finfo->name); new_entry->my_stat.st_size = finfo->size; new_entry->my_stat.st_mtime = finfo->mtime; @@ -469,12 +470,12 @@ loaddir_helper (file_info * finfo, const char *mask, void *entry) new_entry->my_stat.st_uid = finfo->uid; new_entry->my_stat.st_gid = finfo->gid; - new_entry->my_stat.st_mode = + new_entry->my_stat.st_mode = /* rw-rw-rw */ S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH; /* if (finfo->mode & aVOLID); nothing similar in real world */ if (finfo->mode & aDIR) - new_entry->my_stat.st_mode |= + new_entry->my_stat.st_mode |= /* drwxrwxrwx */ S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; else new_entry->my_stat.st_mode |= S_IFREG; /* if not dir, regular file? */ @@ -484,10 +485,11 @@ loaddir_helper (file_info * finfo, const char *mask, void *entry) if (finfo->mode & aRONLY) new_entry->my_stat.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); - DEBUG (3, (" %-30s%7.7s%8.0f %s", - CNV_LANG (finfo->name), - attrib_string (finfo->mode), - (double) finfo->size, asctime (LocalTime (&t)))); + DEBUG (entry ? 3 : 6, (" %-30s%7.7s%8.0f %s", + CNV_LANG (finfo->name), + attrib_string (finfo->mode), + (double) finfo->size, + asctime (LocalTime (&t)))); } /* takes "/foo/bar/file" and gives malloced "\\foo\\bar\\file" */ @@ -1263,12 +1265,18 @@ fake_share_stat(const char *server_url, const char *path, struct stat *buf) /* stat a single file, get_remote_stat callback */ static dir_entry *single_entry; -static void -statfile_helper (file_info * finfo, const char *mask, void * entry) +/* stat a single file */ +static int +get_remote_stat (smbfs_connection * sc, char *path, struct stat *buf) { - time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */ + uint16 attribute = aDIR | aSYSTEM | aHIDDEN; + char *mypath = path; -#if 0 /* single_entry is never free()d now. And only my_stat is used */ + DEBUG (3, ("get_remote_stat(): mypath:%s\n", mypath)); + + convert_path (&mypath, FALSE); + +#if 0 /* single_entry is never free()d now. And only my_stat is used */ single_entry = g_new (dir_entry, 1); single_entry->text = dos_to_unix (g_strdup (finfo->name), 1); @@ -1278,57 +1286,20 @@ statfile_helper (file_info * finfo, const char *mask, void * entry) if (!single_entry) single_entry = g_new0 (dir_entry, 1); - single_entry->my_stat.st_size = finfo->size; - single_entry->my_stat.st_mtime = finfo->mtime; - single_entry->my_stat.st_atime = finfo->atime; - single_entry->my_stat.st_ctime = finfo->ctime; - single_entry->my_stat.st_uid = finfo->uid; - single_entry->my_stat.st_gid = finfo->gid; + if (cli_list + (sc->cli, mypath, attribute, loaddir_helper, single_entry) < 1) { + my_errno = ENOENT; + g_free (mypath); + return -1; /* cli_list returns number of files */ + } - single_entry->my_stat.st_mode = /* rw-rw-rw */ - S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH; - -/* if (finfo->mode & aVOLID); nothing similar in real world */ - if (finfo->mode & aDIR) /* drwxrwxrwx */ - single_entry->my_stat.st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; - else /* if not dir, regular file? */ - single_entry->my_stat.st_mode |= S_IFREG; -/* if (finfo->mode & aARCH); DOS archive */ -/* if (finfo->mode & aHIDDEN); like a dot file? */ -/* if (finfo->mode & aSYSTEM); like a kernel? */ - if (finfo->mode & aRONLY) - single_entry->my_stat.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); - - DEBUG (6, (" %-30s%7.7s%8.0f %s", - CNV_LANG (finfo->name), - attrib_string (finfo->mode), - (double) finfo->size, asctime (LocalTime (&t)))); -} - -/* stat a single file */ -static int -get_remote_stat(smbfs_connection *sc, char *path, struct stat *buf) -{ - uint16 attribute = aDIR | aSYSTEM | aHIDDEN; - char *mypath = path; - - DEBUG(3, ("get_remote_stat(): mypath:%s\n", mypath)); - - convert_path(&mypath, FALSE); - - if (cli_list(sc->cli, mypath, attribute, statfile_helper, &single_entry) < 1) { - my_errno = ENOENT; - g_free (mypath); - return -1; /* cli_list returns number of files */ - } - - memcpy(buf, &single_entry->my_stat, sizeof(struct stat)); + memcpy (buf, &single_entry->my_stat, sizeof (struct stat)); /* don't free here, use for smbfs_fstat() */ /* g_free(single_entry->text); g_free(single_entry); */ - g_free (mypath); - return 0; + g_free (mypath); + return 0; } static int