VirtualBox

Changeset 4796 in vbox


Ignore:
Timestamp:
Sep 14, 2007 1:41:10 PM (17 years ago)
Author:
vboxsync
Message:

Fixed a problem with \'rename\' in shared folders, Linux guests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/sharedfolders/dirops.c

    r4743 r4796  
    537537           struct inode *new_parent, struct dentry *new_dentry)
    538538{
    539         int err, rc;
     539        int err = 0, rc = VINF_SUCCESS;
    540540        struct sf_glob_info *sf_g = GET_GLOB_INFO (old_parent->i_sb);
    541         struct sf_inode_info *sf_old_i = GET_INODE_INFO (old_parent);
    542         struct sf_inode_info *sf_new_i = GET_INODE_INFO (new_parent);
    543         SHFLSTRING *old_path;
    544         SHFLSTRING *new_path;
    545         int is_dir = ((old_dentry->d_inode->i_mode & S_IFDIR) != 0);
    546 
    547         TRACE ();
    548         BUG_ON (!sf_old_i);
    549         BUG_ON (!sf_new_i);
     541
     542        TRACE ();
    550543
    551544        if (sf_g != GET_GLOB_INFO (new_parent->i_sb)) {
    552545                LogFunc(("rename with different roots\n"));
    553                 return -EINVAL;
    554         }
    555 
    556         err = sf_path_from_dentry (__func__, sf_g, sf_old_i,
    557                                    old_dentry, &old_path);
    558         if (err) {
    559                 LogFunc(("failed to create old path\n"));
    560                 return err;
    561         }
    562 
    563         err = sf_path_from_dentry (__func__, sf_g, sf_new_i,
    564                                    new_dentry, &new_path);
    565         if (err) {
    566                 LogFunc(("failed to create new path\n"));
    567                 goto fail0;
    568         }
    569 
    570         rc = vboxCallRename (&client_handle, &sf_g->map, old_path,
    571                              new_path, is_dir ? 0 : SHFL_RENAME_FILE);
    572         if (VBOX_FAILURE (rc)) {
    573                 switch (rc) {
    574                         /** @todo we need a function to convert VBox error
    575                             codes back to Linux. */
    576                         case VERR_ACCESS_DENIED:
    577                                 err = -EACCES;
    578                                 goto fail1;
    579                         case VERR_DEV_IO_ERROR:
    580                                 return -EBUSY;
    581                                 goto fail1;
    582                         case VERR_INVALID_POINTER:
    583                                 return -EFAULT;
    584                                 goto fail1;
    585                         case VERR_FILE_NOT_FOUND:
    586                         case VERR_PATH_NOT_FOUND:
    587                                 err = -ENOENT;
    588                                 goto fail1;
    589 
    590                         default:
    591                                 err = -EPROTO;
     546                err = -EINVAL;
     547        } else {
     548                struct sf_inode_info *sf_old_i = GET_INODE_INFO (old_parent);
     549                struct sf_inode_info *sf_new_i = GET_INODE_INFO (new_parent);
     550                /* As we save the relative path inside the inode structure, we need to change
     551                  this if the rename is successful. */
     552                struct sf_inode_info *sf_file_i = GET_INODE_INFO (old_dentry->d_inode);
     553                SHFLSTRING *old_path;
     554                SHFLSTRING *new_path;
     555
     556                BUG_ON (!sf_old_i);
     557                BUG_ON (!sf_new_i);
     558                BUG_ON (!sf_file_i);
     559
     560                old_path = sf_file_i->path;
     561                err = sf_path_from_dentry (__func__, sf_g, sf_new_i,
     562                                          new_dentry, &new_path);
     563                if (err) {
     564                        LogFunc(("failed to create new path\n"));
     565                } else {
     566                        int is_dir = ((old_dentry->d_inode->i_mode & S_IFDIR) != 0);
     567
     568                        rc = vboxCallRename (&client_handle, &sf_g->map, old_path,
     569                                             new_path, is_dir ? 0 : SHFL_RENAME_FILE | SHFL_RENAME_REPLACE_IF_EXISTS);
     570                        if (RT_SUCCESS(rc)) {
     571                                kfree (old_path);
     572                                sf_new_i->force_restat = 1;
     573                                sf_old_i->force_restat = 1; /* XXX: needed? */
     574                                /* Set the new relative path in the inode. */
     575                                sf_file_i->path = new_path;
     576                        } else {
    592577                                LogFunc(("vboxCallRename failed rc=%Vrc\n", rc));
    593                                 goto fail1;
    594                 }
    595         }
    596 
    597         err = 0;
    598 
    599         sf_new_i->force_restat = 1;
    600         sf_old_i->force_restat = 1; /* XXX: needed? */
    601  fail1:
    602         kfree (old_path);
    603  fail0:
    604         kfree (new_path);
     578                                switch (rc) {
     579                                /** @todo we need a function to convert VBox error
     580                                    codes back to Linux. */
     581                                case VERR_ACCESS_DENIED:
     582                                        err = -EACCES;
     583                                        break;
     584                                case VERR_DEV_IO_ERROR:
     585                                        err = -EBUSY;
     586                                        break;
     587                                case VERR_INVALID_POINTER:
     588                                        err = -EFAULT;
     589                                        break;
     590                                case VERR_FILE_NOT_FOUND:
     591                                case VERR_PATH_NOT_FOUND:
     592                                        err = -ENOENT;
     593                                        break;
     594                                default:
     595                                        err = -EPROTO;
     596                                }
     597                        }
     598                        if (0 != err) {
     599                                kfree (new_path);
     600                        }
     601                }
     602        }
    605603        return err;
    606604}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette