Logo Search packages:      
Sourcecode: samba-doc-ja version File versions

int smbc_getdents ( unsigned int  dh,
struct smbc_dirent dirp,
int  count 
)

Get multiple directory entries.

smbc_getdents() reads as many dirent structures from the an open directory handle into a specified memory area as will fit.

Parameters:
dh Valid directory as returned by smbc_opendir()
dirp pointer to buffer that will receive the directory entries.
count The size of the dirp buffer in bytes
Returns:
If any dirents returned, return will indicate the total size. If there were no more dirents available, 0 is returned. < 0 indicates an error.
  • EBADF Invalid directory handle
  • EINVAL Result buffer is too small or smbc_init not called.
  • ENOENT No such directory.
See also:
, smbc_dirent, smbc_readdir(), smbc_open()
Todo:
Are errno values complete and correct?
Todo:
Add example code so people know how to parse buffers.

Definition at line 1957 of file libsmbclient.c.

References smbc_dirent::namelen.

{
      struct smbc_file *fe;
      struct smbc_dir_list *dir;
      int rem = count, reqd;
      char *ndir = (char *)dirp;

      /* Check that all is ok first ... */

      if (!smbc_initialized) {

            errno = EINVAL;
            return -1;

      }

      if (fd < smbc_start_fd || fd >= (smbc_start_fd + SMBC_MAX_FD)) {

            errno = EBADF;
            return -1;

      }

      fe = smbc_file_table[fd - smbc_start_fd];

      if (!fe) {

            errno = EBADF;
            return -1;
    
      }

      if (fe->file != False) { /* FIXME, should be dir, perhaps */

            errno = ENOTDIR;
            return -1;

      }

      /* 
       * Now, retrieve the number of entries that will fit in what was passed
       * We have to figure out if the info is in the list, or we need to 
       * send a request to the server to get the info.
       */

      while ((dir = fe->dir_next)) {
            struct smbc_dirent *dirent;

            if (!dir->dirent) {

                  errno = ENOENT;  /* Bad error */
                  return -1;

            }

            if (rem < (reqd = (sizeof(struct smbc_dirent) + dir->dirent->namelen + 
                           dir->dirent->commentlen + 1))) {

                  if (rem < count) { /* We managed to copy something */

                        errno = 0;
                        return count - rem;

                  }
                  else { /* Nothing copied ... */

                        errno = EINVAL;  /* Not enough space ... */
                        return -1;

                  }

            }

            dirent = dir->dirent;

            memcpy(ndir, dirent, reqd); /* Copy the data in ... */
    
            ((struct smbc_dirent *)ndir)->comment = 
                  (char *)(((struct smbc_dirent *)ndir)->name + dirent->namelen + 1);

            ndir += reqd;

            rem -= reqd;

            fe->dir_next = dir = dir -> next;
      }

      if (rem == count)
            return 0;
      else 
            return count - rem;

}


Generated by  Doxygen 1.6.0   Back to index