VirtualBox

Ignore:
Timestamp:
Apr 13, 2010 2:14:07 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
59994
Message:

SharedFolders/linux: Don't close an inode for a regular file after it was created with sf_create(). We assume that this inode will be opened with sf_reg_open() and later closed with sf_reg_close(). Fixes copying of read-only files on shared folders.

File:
1 edited

Legend:

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

    r24320 r28253  
    296296                        goto fail1;
    297297                }
     298                sf_new_i->handle = SHFL_HANDLE_NIL;
    298299
    299300                ino = iunique (parent->i_sb, 1);
     
    338339sf_instantiate (const char *caller, struct inode *parent,
    339340                struct dentry *dentry, SHFLSTRING *path,
    340                 RTFSOBJINFO *info)
     341                RTFSOBJINFO *info, SHFLHANDLE handle)
    341342{
    342343        int err;
     
    379380
    380381#if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
    381                 unlock_new_inode(inode);
    382 #endif
    383 
     382        unlock_new_inode(inode);
     383#endif
     384
     385        /* Store this handle if we leave the handle open. */
     386        sf_new_i->handle = handle;
    384387        return 0;
    385388
     
    392395
    393396static int
    394 sf_create_aux (struct inode *parent, struct dentry *dentry, int mode, int dirop)
     397sf_create_aux (struct inode *parent, struct dentry *dentry, int mode, int fDirectory)
    395398{
    396399        int rc, err;
     
    418421                | SHFL_CF_ACT_FAIL_IF_EXISTS
    419422                | SHFL_CF_ACCESS_READWRITE
    420                 | (dirop ? SHFL_CF_DIRECTORY : 0)
     423                | (fDirectory ? SHFL_CF_DIRECTORY : 0)
    421424                ;
    422425
    423426        params.Info.Attr.fMode = 0
    424                 | (dirop ? RTFS_TYPE_DIRECTORY : RTFS_TYPE_FILE)
     427                | (fDirectory ? RTFS_TYPE_DIRECTORY : RTFS_TYPE_FILE)
    425428                | (mode & S_IRWXUGO)
    426429                ;
     
    433436        }
    434437
    435         LogFunc(("calling vboxCallCreate, folder %s, flags %#x\n",
     438        LogFunc(("sf_create_aux: calling vboxCallCreate, folder %s, flags %#x\n",
    436439                 path->String.utf8, params.CreateFlags));
    437440        rc = vboxCallCreate (&client_handle, &sf_g->map, path, &params);
     
    442445                }
    443446                err = -EPROTO;
    444                 LogFunc(("(%d): vboxCallCreate(%s) failed rc=%Rrc\n", dirop,
    445                          sf_i->path->String.utf8, rc));
     447                LogFunc(("(%d): vboxCallCreate(%s) failed rc=%Rrc\n",
     448                         fDirectory, sf_i->path->String.utf8, rc));
    446449                goto fail0;
    447450        }
     
    449452        if (params.Result != SHFL_FILE_CREATED) {
    450453                err = -EPERM;
    451                 LogFunc(("(%d): could not create file %s result=%d\n", dirop,
    452                          sf_i->path->String.utf8, params.Result));
     454                LogFunc(("(%d): could not create file %s result=%d\n",
     455                         fDirectory, sf_i->path->String.utf8, params.Result));
    453456                goto fail0;
    454457        }
    455458
    456         err = sf_instantiate (__func__, parent, dentry, path, &params.Info);
     459        err = sf_instantiate (__func__, parent, dentry, path, &params.Info,
     460                             fDirectory ? SHFL_HANDLE_NIL : params.Handle);
    457461        if (err) {
    458462                LogFunc(("(%d): could not instantiate dentry for %s err=%d\n",
    459                          dirop, sf_i->path->String.utf8, err));
     463                         fDirectory, sf_i->path->String.utf8, err));
    460464                goto fail1;
    461465        }
    462466
    463         rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    464         if (RT_FAILURE (rc)) {
    465                 LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", dirop, rc));
     467        /*
     468         * Don't close this handle right now. We assume that the same file is
     469         * opened with sf_reg_open() and later closed with sf_reg_close(). Save
     470         * the handle in between. Does not apply to directories. True?
     471         */
     472        if (fDirectory)
     473        {
     474                rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
     475                if (RT_FAILURE (rc)) {
     476                        LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", fDirectory, rc));
     477                }
    466478        }
    467479
     
    472484        rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    473485        if (RT_FAILURE (rc)) {
    474                 LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", dirop, rc));
     486                LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", fDirectory, rc));
    475487        }
    476488
     
    499511
    500512static int
    501 sf_unlink_aux (struct inode *parent, struct dentry *dentry, int dirop)
     513sf_unlink_aux (struct inode *parent, struct dentry *dentry, int fDirectory)
    502514{
    503515        int rc, err;
     
    515527
    516528        rc = vboxCallRemove (&client_handle, &sf_g->map, path,
    517                              dirop ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
     529                             fDirectory ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
    518530        if (RT_FAILURE (rc)) {
    519                 LogFunc(("(%d): vboxCallRemove(%s) failed rc=%Rrc\n", dirop,
     531                LogFunc(("(%d): vboxCallRemove(%s) failed rc=%Rrc\n", fDirectory,
    520532                         path->String.utf8, rc));
    521533                         err = -RTErrConvertToErrno (rc);
Note: See TracChangeset for help on using the changeset viewer.

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