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

int smbc_rename ( const char *  ourl,
const char *  nurl 

Rename or move a file or directory.

ourl The original smb url (source url) of file or directory to be moved
nurl The new smb url (destination url) of the file or directory after the move. Currently nurl must be on the same share as ourl.
0 on success, < 0 on error with errno set:
  • EISDIR nurl is an existing directory, but ourl is not a directory.
  • EEXIST nurl is a non-empty directory, i.e., contains entries other than "." and ".."
  • EINVAL The new url contained a path prefix of the old, or, more generally, an attempt was made to make a directory a subdirectory of itself or smbc_init not called.
  • ENOTDIR A component used as a directory in ourl or nurl path is not, in fact, a directory. Or, ourl is a directory, and newpath exists but is not a directory.
  • EACCES or EPERM Write access to the directory containing ourl or nurl is not allowed for the process's effective uid, or one of the directories in ourl or nurl did not allow search (execute) permission, or ourl was a directory and did not allow write permission.
  • ENOENT A directory component in ourl or nurl does not exist.
  • EXDEV Rename across shares not supported.
  • ENOMEM Insufficient kernel memory was available.
  • EEXIST The target file, nurl, already exists.
Are we going to support copying when urls are not on the same share? I say no... NOTE. I agree for the moment.

Definition at line 1000 of file libsmbclient.c.

      fstring server1, share1, server2, share2, user1, user2, password1, password2, workgroup;
      pstring path1, path2;
      struct smbc_server *srv = NULL;

      if (!smbc_initialized) {

            errno = EINVAL;  /* Best I can think of ... */
            return -1;

      if (!oname || !nname) {

            errno = EINVAL;
            return -1;

      DEBUG(4, ("smbc_rename(%s,%s)\n", oname, nname));

      smbc_parse_path(oname, server1, share1, path1, user1, password1);

      if (user1[0] == (char)0) pstrcpy(user1, smbc_user);

      smbc_parse_path(nname, server2, share2, path2, user2, password2);

      if (user2[0] == (char)0) pstrcpy(user2, smbc_user);

      if (strcmp(server1, server2) || strcmp(share1, share2) ||
          strcmp(user1, user2)) {

            /* Can't rename across file systems, or users?? */

            errno = EXDEV;
            return -1;


      pstrcpy(workgroup, lp_workgroup());

      srv = smbc_server(server1, share1, workgroup, user1, password1);
      if (!srv) {

            return -1;


      if (!cli_rename(&srv->cli, path1, path2)) {
            int eno = smbc_errno(&srv->cli);

            if (eno != EEXIST ||
                !cli_unlink(&srv->cli, path2) ||
                !cli_rename(&srv->cli, path1, path2)) {

                  errno = eno;
                  return -1;


      return 0; /* Success */


Generated by  Doxygen 1.6.0   Back to index