VirtualBox

Changeset 30153 in vbox


Ignore:
Timestamp:
Jun 10, 2010 4:23:36 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62575
Message:

Linux shared folders: spaces

Location:
trunk/src/VBox/Additions/linux/sharedfolders
Files:
6 edited

Legend:

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

    r30150 r30153  
    2020
    2121static int
    22 sf_dir_open (struct inode *inode, struct file *file)
     22sf_dir_open(struct inode *inode, struct file *file)
    2323{
    2424        int rc;
    2525        int err;
    26         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     26        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    2727        struct sf_dir_info *sf_d;
    28         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
     28        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
    2929        SHFLCREATEPARMS params;
    3030
    31         TRACE ();
    32         BUG_ON (!sf_g);
    33         BUG_ON (!sf_i);
     31        TRACE();
     32        BUG_ON(!sf_g);
     33        BUG_ON(!sf_i);
    3434
    3535        if (file->private_data) {
     
    4141        RT_ZERO(params);
    4242
    43         sf_d = sf_dir_info_alloc ();
     43        sf_d = sf_dir_info_alloc();
    4444
    4545        if (!sf_d) {
     
    5858        LogFunc(("sf_dir_open: calling vboxCallCreate, folder %s, flags %#x\n",
    5959                 sf_i->path->String.utf8, params.CreateFlags));
    60         rc = vboxCallCreate (&client_handle, &sf_g->map, sf_i->path, &params);
    61         if (RT_FAILURE (rc)) {
     60        rc = vboxCallCreate(&client_handle, &sf_g->map, sf_i->path, &params);
     61        if (RT_FAILURE(rc)) {
    6262                LogFunc(("vboxCallCreate(%s) failed rc=%Rrc\n",
    6363                         sf_i->path->String.utf8, rc));
    64                 sf_dir_info_free (sf_d);
     64                sf_dir_info_free(sf_d);
    6565                return -EPERM;
    6666        }
     
    6868        if (params.Result != SHFL_FILE_EXISTS) {
    6969                LogFunc(("directory %s does not exist\n", sf_i->path->String.utf8));
    70                 sf_dir_info_free (sf_d);
     70                sf_dir_info_free(sf_d);
    7171                return -ENOENT;
    7272        }
    7373
    74         err = sf_dir_read_all (sf_g, sf_i, sf_d, params.Handle);
     74        err = sf_dir_read_all(sf_g, sf_i, sf_d, params.Handle);
    7575        if (err) {
    76                 rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    77                 if (RT_FAILURE (rc)) {
     76                rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     77                if (RT_FAILURE(rc)) {
    7878                        LogFunc(("vboxCallClose(%s) after err=%d failed rc=%Rrc\n",
    7979                                 sf_i->path->String.utf8, err, rc));
    8080                }
    81                 sf_dir_info_free (sf_d);
     81                sf_dir_info_free(sf_d);
    8282                return err;
    8383        }
    8484
    8585
    86         rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    87         if (RT_FAILURE (rc)) {
     86        rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     87        if (RT_FAILURE(rc)) {
    8888                LogFunc(("vboxCallClose(%s) failed rc=%Rrc\n",
    8989                          sf_i->path->String.utf8, rc));
     
    9898   directory and deallocate our own internal buffers */
    9999static int
    100 sf_dir_release (struct inode *inode, struct file *file)
    101 {
    102         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
    103 
    104         TRACE ();
    105         BUG_ON (!sf_i);
     100sf_dir_release(struct inode *inode, struct file *file)
     101{
     102        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
     103
     104        TRACE();
     105        BUG_ON(!sf_i);
    106106
    107107        if (file->private_data) {
    108                 sf_dir_info_free (file->private_data);
     108                sf_dir_info_free(file->private_data);
    109109        }
    110110        return 0;
     
    117117   -errno  some form of error*/
    118118static int
    119 sf_getdent (struct file *dir, char d_name[NAME_MAX])
     119sf_getdent(struct file *dir, char d_name[NAME_MAX])
    120120{
    121121        loff_t cur;
     
    126126        struct list_head *pos, *list;
    127127
    128         TRACE ();
    129 
    130         sf_g = GET_GLOB_INFO (dir->f_dentry->d_inode->i_sb);
     128        TRACE();
     129
     130        sf_g = GET_GLOB_INFO(dir->f_dentry->d_inode->i_sb);
    131131        sf_d = dir->private_data;
    132132
    133         BUG_ON (!sf_g);
    134         BUG_ON (!sf_d);
     133        BUG_ON(!sf_g);
     134        BUG_ON(!sf_d);
    135135
    136136        inode = dir->f_dentry->d_inode;
    137137        sf_i = GET_INODE_INFO(inode);
    138138
    139         BUG_ON (!sf_i);
     139        BUG_ON(!sf_i);
    140140
    141141        if (sf_i->force_reread)
     
    156156                LogFunc(("sf_getdent: calling vboxCallCreate, folder %s, flags %#x\n",
    157157                            sf_i->path->String.utf8, params.CreateFlags));
    158                 rc = vboxCallCreate (&client_handle, &sf_g->map, sf_i->path, &params);
    159                 if (RT_FAILURE (rc)) {
     158                rc = vboxCallCreate(&client_handle, &sf_g->map, sf_i->path, &params);
     159                if (RT_FAILURE(rc)) {
    160160                    LogRel(("open failed %d\n", rc));
    161161                    LogFunc(("vboxCallCreate(%s) failed rc=%Rrc\n",
     
    167167                    LogRel(("not exist %x\n", params.Result));
    168168                    LogFunc(("directory %s does not exist\n", sf_i->path->String.utf8));
    169                     sf_dir_info_free (sf_d);
     169                    sf_dir_info_free(sf_d);
    170170                    return -ENOENT;
    171171                }
    172172 
    173                 sf_dir_info_empty (sf_d);
    174                 err = sf_dir_read_all (sf_g, sf_i, sf_d, params.Handle);
    175                 rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    176                 if (RT_FAILURE (rc)) {
     173                sf_dir_info_empty(sf_d);
     174                err = sf_dir_read_all(sf_g, sf_i, sf_d, params.Handle);
     175                rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     176                if (RT_FAILURE(rc)) {
    177177                    LogFunc(("vboxCallClose(%s) failed rc=%Rrc\n",
    178178                             sf_i->path->String.utf8, rc));
     
    185185        cur = 0;
    186186        list = &sf_d->info_list;
    187         list_for_each (pos, list) {
     187        list_for_each(pos, list) {
    188188                struct sf_dir_buf *b;
    189189                SHFLDIRINFO *info;
     
    192192                char *name_ptr;
    193193
    194                 b = list_entry (pos, struct sf_dir_buf, head);
     194                b = list_entry(pos, struct sf_dir_buf, head);
    195195                if (dir->f_pos >= cur + b->nb_entries) {
    196196                        cur += b->nb_entries;
     
    201201                        size_t size;
    202202
    203                         size = offsetof (SHFLDIRINFO, name.String) + info->name.u16Size;
     203                        size = offsetof(SHFLDIRINFO, name.String) + info->name.u16Size;
    204204                        info = (SHFLDIRINFO *) ((uintptr_t) info + size);
    205205                }
     
    208208                name_len = info->name.u16Length;
    209209
    210                 return sf_nlscpy (sf_g, d_name, NAME_MAX, name_ptr, name_len);
     210                return sf_nlscpy(sf_g, d_name, NAME_MAX, name_ptr, name_len);
    211211        }
    212212        return 1;
     
    237237sf_dir_read (struct file *dir, void *opaque, filldir_t filldir)
    238238{
    239         TRACE ();
     239        TRACE();
    240240        for (;;) {
    241241                int err;
     
    244244                char d_name[NAME_MAX];
    245245
    246                 err = sf_getdent (dir, d_name);
     246                err = sf_getdent(dir, d_name);
    247247                switch (err) {
    248248                        case 1:
     
    269269                }
    270270
    271                 err = filldir (opaque, d_name, strlen (d_name),
     271                err = filldir(opaque, d_name, strlen(d_name),
    272272                               dir->f_pos, fake_ino, DT_UNKNOWN);
    273273                if (err) {
     
    281281        }
    282282
    283         BUG ();
     283        BUG();
    284284}
    285285
     
    302302   returned in case of succes and "negative" pointer on error */
    303303static struct dentry *
    304 sf_lookup (struct inode *parent, struct dentry *dentry
    305 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     304sf_lookup(struct inode *parent, struct dentry *dentry
     305#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    306306           , struct nameidata *nd
    307307#endif
     
    316316        RTFSOBJINFO fsinfo;
    317317
    318         TRACE ();
    319         sf_g = GET_GLOB_INFO (parent->i_sb);
    320         sf_i = GET_INODE_INFO (parent);
    321 
    322         BUG_ON (!sf_g);
    323         BUG_ON (!sf_i);
    324 
    325         err = sf_path_from_dentry (__func__, sf_g, sf_i, dentry, &path);
     318        TRACE();
     319        sf_g = GET_GLOB_INFO(parent->i_sb);
     320        sf_i = GET_INODE_INFO(parent);
     321
     322        BUG_ON(!sf_g);
     323        BUG_ON(!sf_i);
     324
     325        err = sf_path_from_dentry(__func__, sf_g, sf_i, dentry, &path);
    326326        if (err) {
    327327                goto fail0;
    328328        }
    329329
    330         err = sf_stat (__func__, sf_g, path, &fsinfo, 1);
     330        err = sf_stat(__func__, sf_g, path, &fsinfo, 1);
    331331        if (err) {
    332332                if (err == -ENOENT) {
     
    338338        }
    339339        else {
    340                 sf_new_i = kmalloc (sizeof (*sf_new_i), GFP_KERNEL);
     340                sf_new_i = kmalloc(sizeof(*sf_new_i), GFP_KERNEL);
    341341                if (!sf_new_i) {
    342342                        LogRelFunc(("could not allocate memory for new inode info\n"));
     
    346346                sf_new_i->handle = SHFL_HANDLE_NIL;
    347347
    348                 ino = iunique (parent->i_sb, 1);
    349 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
    350                 inode = iget_locked (parent->i_sb, ino);
     348                ino = iunique(parent->i_sb, 1);
     349#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
     350                inode = iget_locked(parent->i_sb, ino);
    351351#else
    352                 inode = iget (parent->i_sb, ino);
     352                inode = iget(parent->i_sb, ino);
    353353#endif
    354354                if (!inode) {
     
    358358                }
    359359
    360                 SET_INODE_INFO (inode, sf_new_i);
    361                 sf_init_inode (sf_g, inode, &fsinfo);
     360                SET_INODE_INFO(inode, sf_new_i);
     361                sf_init_inode(sf_g, inode, &fsinfo);
    362362                sf_new_i->path = path;
    363363
    364 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
     364#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
    365365                unlock_new_inode(inode);
    366366#endif
     
    370370        dentry->d_time = jiffies;
    371371        dentry->d_op = &sf_dentry_ops;
    372         d_add (dentry, inode);
     372        d_add(dentry, inode);
    373373        return NULL;
    374374
    375375 fail2:
    376         kfree (sf_new_i);
     376        kfree(sf_new_i);
    377377 fail1:
    378         kfree (path);
     378        kfree(path);
    379379 fail0:
    380         return ERR_PTR (err);
     380        return ERR_PTR(err);
    381381}
    382382
     
    385385   dentry */
    386386static int
    387 sf_instantiate (const char *caller, struct inode *parent,
     387sf_instantiate(const char *caller, struct inode *parent,
    388388                struct dentry *dentry, SHFLSTRING *path,
    389389                RTFSOBJINFO *info, SHFLHANDLE handle)
     
    393393        struct inode *inode;
    394394        struct sf_inode_info *sf_new_i;
    395         struct sf_glob_info *sf_g = GET_GLOB_INFO (parent->i_sb);
    396 
    397         TRACE ();
    398         BUG_ON (!sf_g);
    399 
    400         sf_new_i = kmalloc (sizeof (*sf_new_i), GFP_KERNEL);
     395        struct sf_glob_info *sf_g = GET_GLOB_INFO(parent->i_sb);
     396
     397        TRACE();
     398        BUG_ON(!sf_g);
     399
     400        sf_new_i = kmalloc(sizeof(*sf_new_i), GFP_KERNEL);
    401401        if (!sf_new_i) {
    402402                LogRelFunc(("could not allocate inode info.  caller=%s\n", caller));
     
    405405        }
    406406
    407         ino = iunique (parent->i_sb, 1);
    408 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
    409         inode = iget_locked (parent->i_sb, ino);
     407        ino = iunique(parent->i_sb, 1);
     408#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
     409        inode = iget_locked(parent->i_sb, ino);
    410410#else
    411         inode = iget (parent->i_sb, ino);
     411        inode = iget(parent->i_sb, ino);
    412412#endif
    413413        if (!inode) {
     
    417417        }
    418418
    419         sf_init_inode (sf_g, inode, info);
     419        sf_init_inode(sf_g, inode, info);
    420420        sf_new_i->path = path;
    421         SET_INODE_INFO (inode, sf_new_i);
     421        SET_INODE_INFO(inode, sf_new_i);
    422422
    423423        dentry->d_time = jiffies;
     
    425425        sf_new_i->force_restat = 1;
    426426
    427         d_instantiate (dentry, inode);
    428 
    429 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
     427        d_instantiate(dentry, inode);
     428
     429#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
    430430        unlock_new_inode(inode);
    431431#endif
     
    436436
    437437 fail1:
    438         kfree (sf_new_i);
     438        kfree(sf_new_i);
    439439 fail0:
    440440        return err;
     
    443443
    444444static int
    445 sf_create_aux (struct inode *parent, struct dentry *dentry, int mode, int fDirectory)
     445sf_create_aux(struct inode *parent, struct dentry *dentry, int mode, int fDirectory)
    446446{
    447447        int rc, err;
    448448        SHFLCREATEPARMS params;
    449449        SHFLSTRING *path;
    450         struct sf_inode_info *sf_i = GET_INODE_INFO (parent);
    451         struct sf_glob_info *sf_g = GET_GLOB_INFO (parent->i_sb);
    452 
    453         TRACE ();
    454         BUG_ON (!sf_i);
    455         BUG_ON (!sf_g);
     450        struct sf_inode_info *sf_i = GET_INODE_INFO(parent);
     451        struct sf_glob_info *sf_g = GET_GLOB_INFO(parent->i_sb);
     452
     453        TRACE();
     454        BUG_ON(!sf_i);
     455        BUG_ON(!sf_g);
    456456
    457457#if 0
    458         printk ("create_aux %s/%s\n", sf_i->path->String.utf8,
     458        printk("create_aux %s/%s\n", sf_i->path->String.utf8,
    459459                dentry->d_name.name);
    460460#endif
     
    466466
    467467        params.CreateFlags = 0
    468                 | SHFL_CF_ACT_CREATE_IF_NEW
    469                 | SHFL_CF_ACT_FAIL_IF_EXISTS
    470                 | SHFL_CF_ACCESS_READWRITE
    471                 | (fDirectory ? SHFL_CF_DIRECTORY : 0)
    472                 ;
     468                           | SHFL_CF_ACT_CREATE_IF_NEW
     469                           | SHFL_CF_ACT_FAIL_IF_EXISTS
     470                           | SHFL_CF_ACCESS_READWRITE
     471                           | (fDirectory ? SHFL_CF_DIRECTORY : 0)
     472                           ;
    473473
    474474        params.Info.Attr.fMode = 0
    475                 | (fDirectory ? RTFS_TYPE_DIRECTORY : RTFS_TYPE_FILE)
    476                 | (mode & S_IRWXUGO)
    477                 ;
     475                               | (fDirectory ? RTFS_TYPE_DIRECTORY : RTFS_TYPE_FILE)
     476                               | (mode & S_IRWXUGO)
     477                               ;
    478478
    479479        params.Info.Attr.enmAdditional = RTFSOBJATTRADD_NOTHING;
    480480
    481         err = sf_path_from_dentry (__func__, sf_g, sf_i, dentry, &path);
     481        err = sf_path_from_dentry(__func__, sf_g, sf_i, dentry, &path);
    482482        if (err) {
    483483                goto fail0;
     
    486486        LogFunc(("sf_create_aux: calling vboxCallCreate, folder %s, flags %#x\n",
    487487                 path->String.utf8, params.CreateFlags));
    488         rc = vboxCallCreate (&client_handle, &sf_g->map, path, &params);
    489         if (RT_FAILURE (rc)) {
     488        rc = vboxCallCreate(&client_handle, &sf_g->map, path, &params);
     489        if (RT_FAILURE(rc)) {
    490490                if (rc == VERR_WRITE_PROTECT) {
    491491                        err = -EROFS;
     
    505505        }
    506506
    507         err = sf_instantiate (__func__, parent, dentry, path, &params.Info,
     507        err = sf_instantiate(__func__, parent, dentry, path, &params.Info,
    508508                             fDirectory ? SHFL_HANDLE_NIL : params.Handle);
    509509        if (err) {
     
    520520        if (fDirectory)
    521521        {
    522                 rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    523                 if (RT_FAILURE (rc)) {
     522                rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     523                if (RT_FAILURE(rc)) {
    524524                        LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", fDirectory, rc));
    525525                }
     
    530530
    531531 fail1:
    532         rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    533         if (RT_FAILURE (rc)) {
     532        rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     533        if (RT_FAILURE(rc)) {
    534534                LogFunc(("(%d): vboxCallClose failed rc=%Rrc\n", fDirectory, rc));
    535535        }
    536536
    537537 fail0:
    538         kfree (path);
     538        kfree(path);
    539539        return err;
    540540}
    541541
    542542static int
    543 sf_create (struct inode *parent, struct dentry *dentry, int mode
    544 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     543sf_create(struct inode *parent, struct dentry *dentry, int mode
     544#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    545545           , struct nameidata *nd
    546546#endif
    547547        )
    548548{
    549         TRACE ();
    550         return sf_create_aux (parent, dentry, mode, 0);
    551 }
    552 
    553 static int
    554 sf_mkdir (struct inode *parent, struct dentry *dentry, int mode)
    555 {
    556         TRACE ();
    557         return sf_create_aux (parent, dentry, mode, 1);
    558 }
    559 
    560 static int
    561 sf_unlink_aux (struct inode *parent, struct dentry *dentry, int fDirectory)
     549        TRACE();
     550        return sf_create_aux(parent, dentry, mode, 0);
     551}
     552
     553static int
     554sf_mkdir(struct inode *parent, struct dentry *dentry, int mode)
     555{
     556        TRACE();
     557        return sf_create_aux(parent, dentry, mode, 1);
     558}
     559
     560static int
     561sf_unlink_aux(struct inode *parent, struct dentry *dentry, int fDirectory)
    562562{
    563563        int rc, err;
    564         struct sf_glob_info *sf_g = GET_GLOB_INFO (parent->i_sb);
    565         struct sf_inode_info *sf_i = GET_INODE_INFO (parent);
     564        struct sf_glob_info *sf_g = GET_GLOB_INFO(parent->i_sb);
     565        struct sf_inode_info *sf_i = GET_INODE_INFO(parent);
    566566        SHFLSTRING *path;
    567567
    568         TRACE ();
    569         BUG_ON (!sf_g);
    570 
    571         err = sf_path_from_dentry (__func__, sf_g, sf_i, dentry, &path);
     568        TRACE();
     569        BUG_ON(!sf_g);
     570
     571        err = sf_path_from_dentry(__func__, sf_g, sf_i, dentry, &path);
    572572        if (err) {
    573573                goto fail0;
    574574        }
    575575
    576         rc = vboxCallRemove (&client_handle, &sf_g->map, path,
     576        rc = vboxCallRemove(&client_handle, &sf_g->map, path,
    577577                             fDirectory ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
    578         if (RT_FAILURE (rc)) {
     578        if (RT_FAILURE(rc)) {
    579579                LogFunc(("(%d): vboxCallRemove(%s) failed rc=%Rrc\n", fDirectory,
    580580                         path->String.utf8, rc));
    581                          err = -RTErrConvertToErrno (rc);
     581                         err = -RTErrConvertToErrno(rc);
    582582                goto fail1;
    583583        }
     
    587587        /* directory content changed */
    588588        sf_i->force_reread = 1;
    589         kfree (path);
     589        kfree(path);
    590590        return 0;
    591591
    592592 fail1:
    593         kfree (path);
     593        kfree(path);
    594594 fail0:
    595595        return err;
     
    597597
    598598static int
    599 sf_unlink (struct inode *parent, struct dentry *dentry)
    600 {
    601         TRACE ();
    602         return sf_unlink_aux (parent, dentry, 0);
    603 }
    604 
    605 static int
    606 sf_rmdir (struct inode *parent, struct dentry *dentry)
    607 {
    608         TRACE ();
    609         return sf_unlink_aux (parent, dentry, 1);
    610 }
    611 
    612 static int
    613 sf_rename (struct inode *old_parent, struct dentry *old_dentry,
     599sf_unlink(struct inode *parent, struct dentry *dentry)
     600{
     601        TRACE();
     602        return sf_unlink_aux(parent, dentry, 0);
     603}
     604
     605static int
     606sf_rmdir(struct inode *parent, struct dentry *dentry)
     607{
     608        TRACE();
     609        return sf_unlink_aux(parent, dentry, 1);
     610}
     611
     612static int
     613sf_rename(struct inode *old_parent, struct dentry *old_dentry,
    614614           struct inode *new_parent, struct dentry *new_dentry)
    615615{
    616616        int err = 0, rc = VINF_SUCCESS;
    617         struct sf_glob_info *sf_g = GET_GLOB_INFO (old_parent->i_sb);
    618 
    619         TRACE ();
    620 
    621         if (sf_g != GET_GLOB_INFO (new_parent->i_sb)) {
     617        struct sf_glob_info *sf_g = GET_GLOB_INFO(old_parent->i_sb);
     618
     619        TRACE();
     620
     621        if (sf_g != GET_GLOB_INFO(new_parent->i_sb)) {
    622622                LogFunc(("rename with different roots\n"));
    623623                err = -EINVAL;
    624624        } else {
    625                 struct sf_inode_info *sf_old_i = GET_INODE_INFO (old_parent);
    626                 struct sf_inode_info *sf_new_i = GET_INODE_INFO (new_parent);
     625                struct sf_inode_info *sf_old_i = GET_INODE_INFO(old_parent);
     626                struct sf_inode_info *sf_new_i = GET_INODE_INFO(new_parent);
    627627                /* As we save the relative path inside the inode structure, we need to change
    628628                  this if the rename is successful. */
    629                 struct sf_inode_info *sf_file_i = GET_INODE_INFO (old_dentry->d_inode);
     629                struct sf_inode_info *sf_file_i = GET_INODE_INFO(old_dentry->d_inode);
    630630                SHFLSTRING *old_path;
    631631                SHFLSTRING *new_path;
    632632
    633                 BUG_ON (!sf_old_i);
    634                 BUG_ON (!sf_new_i);
    635                 BUG_ON (!sf_file_i);
     633                BUG_ON(!sf_old_i);
     634                BUG_ON(!sf_new_i);
     635                BUG_ON(!sf_file_i);
    636636
    637637                old_path = sf_file_i->path;
    638                 err = sf_path_from_dentry (__func__, sf_g, sf_new_i,
     638                err = sf_path_from_dentry(__func__, sf_g, sf_new_i,
    639639                                          new_dentry, &new_path);
    640640                if (err) {
     
    643643                        int is_dir = ((old_dentry->d_inode->i_mode & S_IFDIR) != 0);
    644644
    645                         rc = vboxCallRename (&client_handle, &sf_g->map, old_path,
     645                        rc = vboxCallRename(&client_handle, &sf_g->map, old_path,
    646646                                             new_path, is_dir ? 0 : SHFL_RENAME_FILE | SHFL_RENAME_REPLACE_IF_EXISTS);
    647647                        if (RT_SUCCESS(rc)) {
    648                                 kfree (old_path);
     648                                kfree(old_path);
    649649                                sf_new_i->force_restat = 1;
    650650                                sf_old_i->force_restat = 1; /* XXX: needed? */
     
    653653                        } else {
    654654                                LogFunc(("vboxCallRename failed rc=%Rrc\n", rc));
    655                                 err = -RTErrConvertToErrno (rc);
     655                                err = -RTErrConvertToErrno(rc);
    656656                        }
    657657                        if (0 != err)
    658                                 kfree (new_path);
     658                                kfree(new_path);
    659659                }
    660660        }
     
    669669        .unlink     = sf_unlink,
    670670        .rename     = sf_rename,
    671 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
     671#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    672672        .revalidate = sf_inode_revalidate
    673673#else
  • trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c

    r28998 r30153  
    7474
    7575static void PANIC_ATTR
    76 panic (const char *fmt, ...)
     76panic(const char *fmt, ...)
    7777{
    7878    va_list ap;
    7979
    80     va_start (ap, fmt);
    81     vfprintf (stderr, fmt, ap);
    82     va_end (ap);
    83     exit (EXIT_FAILURE);
     80    va_start(ap, fmt);
     81    vfprintf(stderr, fmt, ap);
     82    va_end(ap);
     83    exit(EXIT_FAILURE);
    8484}
    8585
    8686static void PANIC_ATTR
    87 panic_err (const char *fmt, ...)
     87panic_err(const char *fmt, ...)
    8888{
    8989    va_list ap;
    9090    int errno_code = errno;
    9191
    92     va_start (ap, fmt);
    93     vfprintf (stderr, fmt, ap);
    94     va_end (ap);
    95     fprintf (stderr, ": %s\n", strerror (errno_code));
    96     exit (EXIT_FAILURE);
     92    va_start(ap, fmt);
     93    vfprintf(stderr, fmt, ap);
     94    va_end(ap);
     95    fprintf(stderr, ": %s\n", strerror(errno_code));
     96    exit(EXIT_FAILURE);
    9797}
    9898
    9999static int
    100 safe_atoi (const char *s, size_t size, int base)
     100safe_atoi(const char *s, size_t size, int base)
    101101{
    102102    char *endptr;
    103     long long int val = strtoll (s, &endptr, base);
     103    long long int val = strtoll(s, &endptr, base);
    104104
    105105    if (val < INT_MIN || val > INT_MAX || endptr < s + size)
    106106    {
    107107        errno = ERANGE;
    108         panic_err ("could not convert %.*s to integer, result = %d",
     108        panic_err("could not convert %.*s to integer, result = %d",
    109109                   (int)size, s, (int) val);
    110110    }
    111     return (int) val;
     111    return (int)val;
    112112}
    113113
    114114static void
    115 process_mount_opts (const char *s, struct opts *opts)
     115process_mount_opts(const char *s, struct opts *opts)
    116116{
    117117    const char *next = s;
     
    180180
    181181        s = next;
    182         next = strchr (s, ',');
     182        next = strchr(s, ',');
    183183        if (!next)
    184184        {
    185             len = strlen (s);
     185            len = strlen(s);
    186186        }
    187187        else
     
    220220                    if (!(val && *val))
    221221                    {
    222                         panic ("%.*s requires an argument (i.e. %.*s=<arg>)\n",
     222                        panic("%.*s requires an argument (i.e. %.*s=<arg>)\n",
    223223                               (int)len, s, (int)len, s);
    224224                    }
     
    256256                case HOUID:
    257257                    /** @todo convert string to id. */
    258                     opts->uid = safe_atoi (val, val_len, 10);
     258                    opts->uid = safe_atoi(val, val_len, 10);
    259259                    break;
    260260                case HOGID:
    261261                    /** @todo convert string to id. */
    262                     opts->gid = safe_atoi (val, val_len, 10);
     262                    opts->gid = safe_atoi(val, val_len, 10);
    263263                    break;
    264264                case HOTTL:
    265                     opts->ttl = safe_atoi (val, val_len, 10);
     265                    opts->ttl = safe_atoi(val, val_len, 10);
    266266                    break;
    267267                case HODMODE:
    268                     opts->dmode = safe_atoi (val, val_len, 8);
     268                    opts->dmode = safe_atoi(val, val_len, 8);
    269269                    break;
    270270                case HOFMODE:
    271                     opts->fmode = safe_atoi (val, val_len, 8);
     271                    opts->fmode = safe_atoi(val, val_len, 8);
    272272                    break;
    273273                case HOUMASK:
    274                     opts->dmask = opts->fmask = safe_atoi (val, val_len, 8);
     274                    opts->dmask = opts->fmask = safe_atoi(val, val_len, 8);
    275275                    break;
    276276                case HODMASK:
    277                     opts->dmask = safe_atoi (val, val_len, 8);
     277                    opts->dmask = safe_atoi(val, val_len, 8);
    278278                    break;
    279279                case HOFMASK:
    280                     opts->fmask = safe_atoi (val, val_len, 8);
     280                    opts->fmask = safe_atoi(val, val_len, 8);
    281281                    break;
    282282                case HOIOCHARSET:
    283                     if (val_len + 1 > sizeof (opts->nls_name))
     283                    if (val_len + 1 > sizeof(opts->nls_name))
    284284                    {
    285                         panic ("iocharset name too long\n");
     285                        panic("iocharset name too long\n");
    286286                    }
    287                     memcpy (opts->nls_name, val, val_len);
     287                    memcpy(opts->nls_name, val, val_len);
    288288                    opts->nls_name[val_len] = 0;
    289289                    break;
    290290                case HOCONVERTCP:
    291                     opts->convertcp = malloc (val_len + 1);
     291                    opts->convertcp = malloc(val_len + 1);
    292292                    if (!opts->convertcp)
    293293                    {
    294                         panic_err ("could not allocate memory");
     294                        panic_err("could not allocate memory");
    295295                    }
    296                     memcpy (opts->convertcp, val, val_len);
     296                    memcpy(opts->convertcp, val, val_len);
    297297                    opts->convertcp[val_len] = 0;
    298298                    break;
     
    308308        if (!handler->name)
    309309        {
    310             fprintf (stderr, "unknown mount option `%.*s'\n", (int)len, s);
    311             fprintf (stderr, "valid options:\n");
     310            fprintf(stderr, "unknown mount option `%.*s'\n", (int)len, s);
     311            fprintf(stderr, "valid options:\n");
    312312
    313313            for (handler = handlers; handler->name; ++handler)
    314314            {
    315315                if (handler->desc)
    316                     fprintf (stderr, "  %-10s%s %s\n", handler->name,
     316                    fprintf(stderr, "  %-10s%s %s\n", handler->name,
    317317                         handler->has_arg ? "=<arg>" : "", handler->desc);
    318318            }
    319             exit (EXIT_FAILURE);
     319            exit(EXIT_FAILURE);
    320320        }
    321321    }
     
    323323
    324324static void
    325 complete (char *host_name, char *mount_point,
     325complete(char *host_name, char *mount_point,
    326326          unsigned long flags, struct opts *opts)
    327327{
     
    331331    struct mntent e;
    332332
    333     m = open_memstream (&buf, &size);
     333    m = open_memstream(&buf, &size);
    334334    if (!m)
    335         panic_err ("could not update mount table (failed to create memstream)");
     335        panic_err("could not update mount table (failed to create memstream)");
    336336
    337337    if (opts->uid)
    338         fprintf (m, "uid=%d,", opts->uid);
     338        fprintf(m, "uid=%d,", opts->uid);
    339339    if (opts->gid)
    340         fprintf (m, "gid=%d,", opts->gid);
     340        fprintf(m, "gid=%d,", opts->gid);
    341341    if (opts->ttl)
    342         fprintf (m, "ttl=%d,", opts->ttl);
     342        fprintf(m, "ttl=%d,", opts->ttl);
    343343    if (*opts->nls_name)
    344         fprintf (m, "iocharset=%s,", opts->nls_name);
     344        fprintf(m, "iocharset=%s,", opts->nls_name);
    345345    if (flags & MS_NOSUID)
    346         fprintf (m, "%s,", MNTOPT_NOSUID);
     346        fprintf(m, "%s,", MNTOPT_NOSUID);
    347347    if (flags & MS_RDONLY)
    348         fprintf (m, "%s,", MNTOPT_RO);
     348        fprintf(m, "%s,", MNTOPT_RO);
    349349    else
    350         fprintf (m, "%s,", MNTOPT_RW);
    351 
    352     fclose (m);
     350        fprintf(m, "%s,", MNTOPT_RW);
     351
     352    fclose(m);
    353353
    354354    if (size > 0)
     
    357357        buf = "defaults";
    358358
    359     f = setmntent (MOUNTED, "a+");
     359    f = setmntent(MOUNTED, "a+");
    360360    if (!f)
    361         panic_err ("could not open mount table for update");
     361        panic_err("could not open mount table for update");
    362362
    363363    e.mnt_fsname = host_name;
     
    368368    e.mnt_passno = 0;
    369369
    370     if (addmntent (f, &e))
     370    if (addmntent(f, &e))
    371371    {
    372372        if (size > 0)
    373373        {
    374             memset (buf, 0, size);
    375             free (buf);
    376         }
    377         panic_err ("could not add an entry to the mount table");
    378     }
    379 
    380     endmntent (f);
     374            memset(buf, 0, size);
     375            free(buf);
     376        }
     377        panic_err("could not add an entry to the mount table");
     378    }
     379
     380    endmntent(f);
    381381
    382382    if (size > 0)
    383383    {
    384         memset (buf, 0, size);
    385         free (buf);
     384        memset(buf, 0, size);
     385        free(buf);
    386386    }
    387387}
    388388
    389389static void
    390 convertcp (char *in_codeset, char *host_name, struct vbsf_mount_info_new *info)
     390convertcp(char *in_codeset, char *host_name, struct vbsf_mount_info_new *info)
    391391{
    392392    char *i = host_name;
    393393    char *o = info->name;
    394     size_t ib = strlen (host_name);
    395     size_t ob = sizeof (info->name) - 1;
     394    size_t ib = strlen(host_name);
     395    size_t ob = sizeof(info->name) - 1;
    396396    iconv_t cd;
    397397
    398     cd = iconv_open ("UTF-8", in_codeset);
     398    cd = iconv_open("UTF-8", in_codeset);
    399399    if (cd == (iconv_t) -1)
    400400    {
    401         panic_err ("could not convert share name, iconv_open `%s' failed",
     401        panic_err("could not convert share name, iconv_open `%s' failed",
    402402                   in_codeset);
    403403    }
     
    405405    while (ib)
    406406    {
    407         size_t c = iconv (cd, &i, &ib, &o, &ob);
     407        size_t c = iconv(cd, &i, &ib, &o, &ob);
    408408        if (c == (size_t) -1)
    409409        {
    410             panic_err ("could not convert share name(%s) at %d",
    411                        host_name, (int)(strlen (host_name) - ib));
     410            panic_err("could not convert share name(%s) at %d",
     411                      host_name, (int)(strlen (host_name) - ib));
    412412        }
    413413    }
     
    485485    mntinf.length       = sizeof(mntinf);
    486486
    487     if (getuid ())
    488         panic ("Only root can mount shared folders from the host.\n");
     487    if (getuid())
     488        panic("Only root can mount shared folders from the host.\n");
    489489
    490490    if (!argv[0])
     
    495495    CT_ASSERT(sizeof(gid_t) == sizeof(int));
    496496
    497     while ((c = getopt (argc, argv, "rwno:h")) != -1)
     497    while ((c = getopt(argc, argv, "rwno:h")) != -1)
    498498    {
    499499        switch (c)
    500500        {
    501501            default:
    502                 fprintf (stderr, "unknown option `%c:%#x'\n", c, c);
     502                fprintf(stderr, "unknown option `%c:%#x'\n", c, c);
    503503            case '?':
    504504            case 'h':
     
    513513
    514514            case 'o':
    515                 process_mount_opts (optarg, &opts);
     515                process_mount_opts(optarg, &opts);
    516516                break;
    517517
     
    529529
    530530    if (opts.convertcp)
    531         convertcp (opts.convertcp, host_name, &mntinf);
     531        convertcp(opts.convertcp, host_name, &mntinf);
    532532    else
    533533    {
    534         if (strlen (host_name) > MAX_HOST_NAME - 1)
    535             panic ("host name is too big\n");
    536 
    537         strcpy (mntinf.name, host_name);
    538     }
    539 
    540     if (strlen (opts.nls_name) > MAX_NLS_NAME - 1)
    541         panic ("%s: the character set name for I/O is too long.\n", argv[0]);
    542 
    543     strcpy (mntinf.nls_name, opts.nls_name);
     534        if (strlen(host_name) > MAX_HOST_NAME - 1)
     535            panic("host name is too big\n");
     536
     537        strcpy(mntinf.name, host_name);
     538    }
     539
     540    if (strlen(opts.nls_name) > MAX_NLS_NAME - 1)
     541        panic("%s: the character set name for I/O is too long.\n", argv[0]);
     542
     543    strcpy(mntinf.nls_name, opts.nls_name);
    544544
    545545    if (opts.ronly)
     
    558558    mntinf.fmask = opts.fmask;
    559559
    560     err = mount (NULL, mount_point, "vboxsf", flags, &mntinf);
     560    err = mount(NULL, mount_point, "vboxsf", flags, &mntinf);
    561561    if (err == -1 && errno == EPROTO)
    562562    {
     
    573573                ++cchCWD;
    574574            /* We checked before that we have enough space */
    575             strcpy (mntinf.name, host_name + cchCWD);
    576         }
    577         err = mount (NULL, mount_point, "vboxsf", flags, &mntinf);
     575            strcpy(mntinf.name, host_name + cchCWD);
     576        }
     577        err = mount(NULL, mount_point, "vboxsf", flags, &mntinf);
    578578    }
    579579    if (err == -1 && errno == EPROTO)
     
    587587        mntinf_old.gid = mntinf.gid;
    588588        mntinf_old.ttl = mntinf.ttl;
    589         err = mount (NULL, mount_point, "vboxsf", flags, &mntinf_old);
     589        err = mount(NULL, mount_point, "vboxsf", flags, &mntinf_old);
    590590    }
    591591    if (err)
    592         panic_err ("%s: mounting failed with the error", argv[0]);
     592        panic_err("%s: mounting failed with the error", argv[0]);
    593593
    594594    if (!nomtab)
    595         complete (host_name, mount_point, flags, &opts);
    596 
    597     exit (EXIT_SUCCESS);
    598 }
     595        complete(host_name, mount_point, flags, &opts);
     596
     597    exit(EXIT_SUCCESS);
     598}
  • trunk/src/VBox/Additions/linux/sharedfolders/regops.c

    r29935 r30153  
    2424
    2525
    26 static void *alloc_bounch_buffer (size_t *tmp_sizep, PRTCCPHYS physp, size_t xfer_size, const char *caller)
     26static void *alloc_bounch_buffer(size_t *tmp_sizep, PRTCCPHYS physp, size_t xfer_size, const char *caller)
    2727{
    2828    size_t tmp_size;
     
    3333    if (tmp_size > 16U*_1K)
    3434        tmp_size = 16U*_1K;
    35     tmp = kmalloc (tmp_size, GFP_KERNEL);
     35    tmp = kmalloc(tmp_size, GFP_KERNEL);
    3636    if (!tmp) {
    3737
    3838        /* fall back on a page sized buffer. */
    39         tmp = kmalloc (PAGE_SIZE, GFP_KERNEL);
     39        tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
    4040        if (!tmp) {
    4141            LogRel(("%s: could not allocate bounce buffer for xfer_size=%zu %s\n", caller, xfer_size));
     
    5050}
    5151
    52 static void free_bounch_buffer (void *tmp)
     52static void free_bounch_buffer(void *tmp)
    5353{
    5454    kfree (tmp);
     
    5858/* fops */
    5959static int
    60 sf_reg_read_aux (const char *caller, struct sf_glob_info *sf_g,
    61                  struct sf_reg_info *sf_r, void *buf, uint32_t *nread,
    62                  uint64_t pos)
     60sf_reg_read_aux(const char *caller, struct sf_glob_info *sf_g,
     61                struct sf_reg_info *sf_r, void *buf, uint32_t *nread,
     62                uint64_t pos)
    6363{
    6464        /** @todo bird: yes, kmap() and kmalloc() input only. Since the buffer is
    6565         *        contiguous in physical memory (kmalloc or single page), we should
    6666         *        use a physical address here to speed things up. */
    67         int rc = vboxCallRead (&client_handle, &sf_g->map, sf_r->handle,
    68                                pos, nread, buf, false /* already locked? */);
    69         if (RT_FAILURE (rc)) {
     67        int rc = vboxCallRead(&client_handle, &sf_g->map, sf_r->handle,
     68                              pos, nread, buf, false /* already locked? */);
     69        if (RT_FAILURE(rc)) {
    7070                LogFunc(("vboxCallRead failed. caller=%s, rc=%Rrc\n",
    7171                         caller, rc));
     
    7676
    7777static int
    78 sf_reg_write_aux (const char *caller, struct sf_glob_info *sf_g,
     78sf_reg_write_aux(const char *caller, struct sf_glob_info *sf_g,
    7979                  struct sf_reg_info *sf_r, void *buf, uint32_t *nwritten,
    8080                  uint64_t pos)
     
    8383         *        contiguous in physical memory (kmalloc or single page), we should
    8484         *        use a physical address here to speed things up. */
    85         int rc = vboxCallWrite (&client_handle, &sf_g->map, sf_r->handle,
     85        int rc = vboxCallWrite(&client_handle, &sf_g->map, sf_r->handle,
    8686                                pos, nwritten, buf, false /* already locked? */);
    87         if (RT_FAILURE (rc)) {
     87        if (RT_FAILURE(rc)) {
    8888                LogFunc(("vboxCallWrite failed. caller=%s, rc=%Rrc\n",
    8989                         caller, rc));
     
    9494
    9595static ssize_t
    96 sf_reg_read (struct file *file, char *buf, size_t size, loff_t *off)
     96sf_reg_read(struct file *file, char *buf, size_t size, loff_t *off)
    9797{
    9898        int err;
     
    103103        ssize_t total_bytes_read = 0;
    104104        struct inode *inode = file->f_dentry->d_inode;
    105         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     105        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    106106        struct sf_reg_info *sf_r = file->private_data;
    107107        loff_t pos = *off;
    108108
    109         TRACE ();
    110         if (!S_ISREG (inode->i_mode)) {
     109        TRACE();
     110        if (!S_ISREG(inode->i_mode)) {
    111111                LogFunc(("read from non regular file %d\n", inode->i_mode));
    112112                return -EINVAL;
     
    119119        }
    120120
    121         tmp = alloc_bounch_buffer (&tmp_size, &tmp_phys, size, __PRETTY_FUNCTION__);
     121        tmp = alloc_bounch_buffer(&tmp_size, &tmp_phys, size, __PRETTY_FUNCTION__);
    122122        if (!tmp)
    123123            return -ENOMEM;
     
    132132                nread = to_read;
    133133
    134                 err = sf_reg_read_aux (__func__, sf_g, sf_r, tmp, &nread, pos);
     134                err = sf_reg_read_aux(__func__, sf_g, sf_r, tmp, &nread, pos);
    135135                if (err)
    136136                        goto fail;
    137137
    138                 if (copy_to_user (buf, tmp, nread)) {
     138                if (copy_to_user(buf, tmp, nread)) {
    139139                        err = -EFAULT;
    140140                        goto fail;
     
    151151
    152152        *off += total_bytes_read;
    153         free_bounch_buffer (tmp);
     153        free_bounch_buffer(tmp);
    154154        return total_bytes_read;
    155155
    156156 fail:
    157         free_bounch_buffer (tmp);
     157        free_bounch_buffer(tmp);
    158158        return err;
    159159}
    160160
    161161static ssize_t
    162 sf_reg_write (struct file *file, const char *buf, size_t size, loff_t *off)
     162sf_reg_write(struct file *file, const char *buf, size_t size, loff_t *off)
    163163{
    164164        int err;
     
    169169        ssize_t total_bytes_written = 0;
    170170        struct inode *inode = file->f_dentry->d_inode;
    171         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
    172         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     171        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
     172        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    173173        struct sf_reg_info *sf_r = file->private_data;
    174174        loff_t pos;
    175175
    176         TRACE ();
    177         BUG_ON (!sf_i);
    178         BUG_ON (!sf_g);
    179         BUG_ON (!sf_r);
    180 
    181         if (!S_ISREG (inode->i_mode)) {
     176        TRACE();
     177        BUG_ON(!sf_i);
     178        BUG_ON(!sf_g);
     179        BUG_ON(!sf_r);
     180
     181        if (!S_ISREG(inode->i_mode)) {
    182182                LogFunc(("write to non regular file %d\n",  inode->i_mode));
    183183                return -EINVAL;
     
    196196                return 0;
    197197
    198         tmp = alloc_bounch_buffer (&tmp_size, &tmp_phys, size, __PRETTY_FUNCTION__);
     198        tmp = alloc_bounch_buffer(&tmp_size, &tmp_phys, size, __PRETTY_FUNCTION__);
    199199        if (!tmp)
    200200                return -ENOMEM;
     
    209209                nwritten = to_write;
    210210
    211                 if (copy_from_user (tmp, buf, to_write)) {
     211                if (copy_from_user(tmp, buf, to_write)) {
    212212                        err = -EFAULT;
    213213                        goto fail;
     
    216216#if 1
    217217                if (VbglR0CanUsePhysPageList()) {
    218                     err = VbglR0SfWritePhysCont (&client_handle, &sf_g->map, sf_r->handle,
    219                                                  pos, &nwritten, tmp_phys);
     218                    err = VbglR0SfWritePhysCont(&client_handle, &sf_g->map, sf_r->handle,
     219                                                pos, &nwritten, tmp_phys);
    220220                    err = RT_FAILURE(err) ? -EPROTO : 0;
    221221                } else
    222222#endif
    223                     err = sf_reg_write_aux (__func__, sf_g, sf_r, tmp, &nwritten, pos);
     223                    err = sf_reg_write_aux(__func__, sf_g, sf_r, tmp, &nwritten, pos);
    224224                if (err)
    225225                        goto fail;
     
    238238
    239239        sf_i->force_restat = 1;
    240         free_bounch_buffer (tmp);
     240        free_bounch_buffer(tmp);
    241241        return total_bytes_written;
    242242
    243243 fail:
    244         free_bounch_buffer (tmp);
     244        free_bounch_buffer(tmp);
    245245        return err;
    246246}
    247247
    248248static int
    249 sf_reg_open (struct inode *inode, struct file *file)
     249sf_reg_open(struct inode *inode, struct file *file)
    250250{
    251251        int rc, rc_linux = 0;
    252         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
    253         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
     252        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
     253        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
    254254        struct sf_reg_info *sf_r;
    255255        SHFLCREATEPARMS params;
    256256
    257         TRACE ();
    258         BUG_ON (!sf_g);
    259         BUG_ON (!sf_i);
     257        TRACE();
     258        BUG_ON(!sf_g);
     259        BUG_ON(!sf_i);
    260260
    261261        LogFunc(("open %s\n", sf_i->path->String.utf8));
    262262
    263         sf_r = kmalloc (sizeof (*sf_r), GFP_KERNEL);
     263        sf_r = kmalloc(sizeof(*sf_r), GFP_KERNEL);
    264264        if (!sf_r) {
    265265                LogRelFunc(("could not allocate reg info\n"));
     
    342342        LogFunc(("sf_reg_open: calling vboxCallCreate, file %s, flags=%#x, %#x\n",
    343343                 sf_i->path->String.utf8 , file->f_flags, params.CreateFlags));
    344         rc = vboxCallCreate (&client_handle, &sf_g->map, sf_i->path, &params);
    345 
    346         if (RT_FAILURE (rc)) {
     344        rc = vboxCallCreate(&client_handle, &sf_g->map, sf_i->path, &params);
     345
     346        if (RT_FAILURE(rc)) {
    347347                LogFunc(("vboxCallCreate failed flags=%d,%#x rc=%Rrc\n",
    348348                         file->f_flags, params.CreateFlags, rc));
    349                 kfree (sf_r);
     349                kfree(sf_r);
    350350                return -RTErrConvertToErrno(rc);
    351351        }
     
    373373
    374374static int
    375 sf_reg_release (struct inode *inode, struct file *file)
     375sf_reg_release(struct inode *inode, struct file *file)
    376376{
    377377        int rc;
    378378        struct sf_reg_info *sf_r;
    379379        struct sf_glob_info *sf_g;
    380         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
    381 
    382         TRACE ();
    383         sf_g = GET_GLOB_INFO (inode->i_sb);
     380        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
     381
     382        TRACE();
     383        sf_g = GET_GLOB_INFO(inode->i_sb);
    384384        sf_r = file->private_data;
    385385
    386         BUG_ON (!sf_g);
    387         BUG_ON (!sf_r);
    388 
    389         rc = vboxCallClose (&client_handle, &sf_g->map, sf_r->handle);
    390         if (RT_FAILURE (rc)) {
     386        BUG_ON(!sf_g);
     387        BUG_ON(!sf_r);
     388
     389        rc = vboxCallClose(&client_handle, &sf_g->map, sf_r->handle);
     390        if (RT_FAILURE(rc)) {
    391391                LogFunc(("vboxCallClose failed rc=%Rrc\n", rc));
    392392        }
    393393
    394         kfree (sf_r);
     394        kfree(sf_r);
    395395        sf_i->file = NULL;
    396396        sf_i->handle = SHFL_HANDLE_NIL;
     
    399399}
    400400
    401 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     401#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    402402static int
    403403sf_reg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
    404 #elif LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     404#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    405405static struct page *
    406 sf_reg_nopage (struct vm_area_struct *vma, unsigned long vaddr, int *type)
     406sf_reg_nopage(struct vm_area_struct *vma, unsigned long vaddr, int *type)
    407407# define SET_TYPE(t) *type = (t)
    408408#else /* LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0) */
    409409static struct page *
    410 sf_reg_nopage (struct vm_area_struct *vma, unsigned long vaddr, int unused)
     410sf_reg_nopage(struct vm_area_struct *vma, unsigned long vaddr, int unused)
    411411# define SET_TYPE(t)
    412412#endif
     
    419419        struct file *file = vma->vm_file;
    420420        struct inode *inode = file->f_dentry->d_inode;
    421         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     421        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    422422        struct sf_reg_info *sf_r = file->private_data;
    423423
    424         TRACE ();
    425 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     424        TRACE();
     425#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    426426        if (vmf->pgoff > vma->vm_end)
    427427                return VM_FAULT_SIGBUS;
    428428#else
    429429        if (vaddr > vma->vm_end) {
    430                 SET_TYPE (VM_FAULT_SIGBUS);
     430                SET_TYPE(VM_FAULT_SIGBUS);
    431431                return NOPAGE_SIGBUS;
    432432        }
    433433#endif
    434434
    435         page = alloc_page (GFP_HIGHUSER);
     435        page = alloc_page(GFP_HIGHUSER);
    436436        if (!page) {
    437437                LogRelFunc(("failed to allocate page\n"));
    438 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     438#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    439439                return VM_FAULT_OOM;
    440440#else
    441                 SET_TYPE (VM_FAULT_OOM);
     441                SET_TYPE(VM_FAULT_OOM);
    442442                return NOPAGE_OOM;
    443443#endif
    444444        }
    445445
    446         buf = kmap (page);
    447 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     446        buf = kmap(page);
     447#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    448448        off = (vmf->pgoff << PAGE_SHIFT);
    449449#else
    450450        off = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
    451451#endif
    452         err = sf_reg_read_aux (__func__, sf_g, sf_r, buf, &nread, off);
     452        err = sf_reg_read_aux(__func__, sf_g, sf_r, buf, &nread, off);
    453453        if (err) {
    454                 kunmap (page);
    455                 put_page (page);
    456 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     454                kunmap(page);
     455                put_page(page);
     456#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    457457                return VM_FAULT_SIGBUS;
    458458#else
    459                 SET_TYPE (VM_FAULT_SIGBUS);
     459                SET_TYPE(VM_FAULT_SIGBUS);
    460460                return NOPAGE_SIGBUS;
    461461#endif
     
    464464        BUG_ON (nread > PAGE_SIZE);
    465465        if (!nread) {
    466 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
    467                 clear_user_page (page_address (page), vmf->pgoff, page);
    468 #elif LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
    469                 clear_user_page (page_address (page), vaddr, page);
    470 #else
    471                 clear_user_page (page_address (page), vaddr);
     466#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
     467                clear_user_page(page_address(page), vmf->pgoff, page);
     468#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
     469                clear_user_page(page_address(page), vaddr, page);
     470#else
     471                clear_user_page(page_address(page), vaddr);
    472472#endif
    473473        }
    474474        else {
    475                 memset (buf + nread, 0, PAGE_SIZE - nread);
    476         }
    477 
    478         flush_dcache_page (page);
    479         kunmap (page);
    480 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     475                memset(buf + nread, 0, PAGE_SIZE - nread);
     476        }
     477
     478        flush_dcache_page(page);
     479        kunmap(page);
     480#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    481481        vmf->page = page;
    482482        return 0;
    483483#else
    484         SET_TYPE (VM_FAULT_MAJOR);
     484        SET_TYPE(VM_FAULT_MAJOR);
    485485        return page;
    486486#endif
     
    488488
    489489static struct vm_operations_struct sf_vma_ops = {
    490 #if LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 25)
     490#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 25)
    491491        .fault = sf_reg_fault
    492492#else
     
    496496
    497497static int
    498 sf_reg_mmap (struct file *file, struct vm_area_struct *vma)
    499 {
    500         TRACE ();
     498sf_reg_mmap(struct file *file, struct vm_area_struct *vma)
     499{
     500        TRACE();
    501501        if (vma->vm_flags & VM_SHARED) {
    502502                LogFunc(("shared mmapping not available\n"));
     
    514514        .release     = sf_reg_release,
    515515        .mmap        = sf_reg_mmap,
    516 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
    517 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 23)
     516#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
     517# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
    518518        .splice_read = generic_file_splice_read,
    519519# else
     
    522522        .aio_read    = generic_file_aio_read,
    523523        .aio_write   = generic_file_aio_write,
    524 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 35)
     524# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
    525525        .fsync       = noop_fsync,
    526526# else
     
    533533
    534534struct inode_operations sf_reg_iops = {
    535 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
     535#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    536536        .revalidate = sf_inode_revalidate
    537537#else
     
    542542
    543543
    544 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     544#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    545545static int
    546546sf_readpage(struct file *file, struct page *page)
    547547{
    548548        struct inode *inode = file->f_dentry->d_inode;
    549         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     549        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    550550        struct sf_reg_info *sf_r = file->private_data;
    551551        uint32_t nread = PAGE_SIZE;
     
    554554        int ret;
    555555
    556         TRACE ();
     556        TRACE();
    557557
    558558        buf = kmap(page);
    559         ret = sf_reg_read_aux (__func__, sf_g, sf_r, buf, &nread, off);
     559        ret = sf_reg_read_aux(__func__, sf_g, sf_r, buf, &nread, off);
    560560        if (ret) {
    561             kunmap (page);
     561            kunmap(page);
    562562            if (PageLocked(page))
    563563                unlock_page(page);
    564564            return ret;
    565565        }
    566         BUG_ON (nread > PAGE_SIZE);
     566        BUG_ON(nread > PAGE_SIZE);
    567567        memset(&buf[nread], 0, PAGE_SIZE - nread);
    568         flush_dcache_page (page);
    569         kunmap (page);
     568        flush_dcache_page(page);
     569        kunmap(page);
    570570        SetPageUptodate(page);
    571571            unlock_page(page);
     
    578578        struct address_space *mapping = page->mapping;
    579579        struct inode *inode = mapping->host;
    580         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
    581         struct sf_inode_info *sf_i = GET_INODE_INFO (inode);
     580        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
     581        struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
    582582        struct file *file = sf_i->file;
    583583        struct sf_reg_info *sf_r = file->private_data;
     
    588588        int err;
    589589
    590         TRACE ();
     590        TRACE();
    591591
    592592        if (page->index >= end_index)
     
    595595        buf = kmap(page);
    596596
    597         err = sf_reg_write_aux (__func__, sf_g, sf_r, buf, &nwritten, off);
     597        err = sf_reg_write_aux(__func__, sf_g, sf_r, buf, &nwritten, off);
    598598        if (err < 0) {
    599599                ClearPageUptodate(page);
     
    614614}
    615615
    616 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24)
     616# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
    617617int
    618618sf_write_begin(struct file *file, struct address_space *mapping, loff_t pos,
    619619               unsigned len, unsigned flags, struct page **pagep, void **fsdata)
    620620{
    621         TRACE ();
     621        TRACE();
    622622
    623623        return simple_write_begin(file, mapping, pos, len, flags, pagep, fsdata);
     
    629629{
    630630        struct inode *inode = mapping->host;
    631         struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb);
     631        struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
    632632        struct sf_reg_info *sf_r = file->private_data;
    633633        void *buf;
     
    636636        int err;
    637637
    638         TRACE ();
     638        TRACE();
    639639
    640640        buf = kmap(page);
    641         err = sf_reg_write_aux (__func__, sf_g, sf_r, buf+from, &nwritten, pos);
     641        err = sf_reg_write_aux(__func__, sf_g, sf_r, buf+from, &nwritten, pos);
    642642        kunmap(page);
    643643
     
    662662        .readpage      = sf_readpage,
    663663        .writepage     = sf_writepage,
    664 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24)
     664# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
    665665        .write_begin   = sf_write_begin,
    666666        .write_end     = sf_write_end,
  • trunk/src/VBox/Additions/linux/sharedfolders/utils.c

    r30150 r30153  
    3535 */
    3636
    37 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
     37#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    3838static void
    39 sf_ftime_from_timespec (time_t *time, RTTIMESPEC *ts)
    40 {
    41         int64_t t = RTTimeSpecGetNano (ts);
    42 
    43         do_div (t, 1000000000);
     39sf_ftime_from_timespec(time_t *time, RTTIMESPEC *ts)
     40{
     41        int64_t t = RTTimeSpecGetNano(ts);
     42
     43        do_div(t, 1000000000);
    4444        *time = t;
    4545}
    4646
    4747static void
    48 sf_timespec_from_ftime (RTTIMESPEC *ts, time_t *time)
     48sf_timespec_from_ftime(RTTIMESPEC *ts, time_t *time)
    4949{
    5050        int64_t t = 1000000000 * *time;
    51         RTTimeSpecSetNano (ts, t);
     51        RTTimeSpecSetNano(ts, t);
    5252}
    5353#else /* >= 2.6.0 */
    5454static void
    55 sf_ftime_from_timespec (struct timespec *tv, RTTIMESPEC *ts)
    56 {
    57         int64_t t = RTTimeSpecGetNano (ts);
     55sf_ftime_from_timespec(struct timespec *tv, RTTIMESPEC *ts)
     56{
     57        int64_t t = RTTimeSpecGetNano(ts);
    5858        int64_t nsec;
    5959
    60         nsec = do_div (t, 1000000000);
     60        nsec = do_div(t, 1000000000);
    6161        tv->tv_sec = t;
    6262        tv->tv_nsec = nsec;
     
    6464
    6565static void
    66 sf_timespec_from_ftime (RTTIMESPEC *ts, struct timespec *tv)
     66sf_timespec_from_ftime(RTTIMESPEC *ts, struct timespec *tv)
    6767{
    6868        int64_t t = (int64_t)tv->tv_nsec + (int64_t)tv->tv_sec * 1000000000;
    69         RTTimeSpecSetNano (ts, t);
     69        RTTimeSpecSetNano(ts, t);
    7070}
    7171#endif /* >= 2.6.0 */
     
    7373/* set [inode] attributes based on [info], uid/gid based on [sf_g] */
    7474void
    75 sf_init_inode (struct sf_glob_info *sf_g, struct inode *inode,
     75sf_init_inode(struct sf_glob_info *sf_g, struct inode *inode,
    7676               RTFSOBJINFO *info)
    7777{
     
    8080        int mode;
    8181
    82         TRACE ();
     82        TRACE();
    8383
    8484        attr = &info->Attr;
    85         is_dir = RTFS_IS_DIRECTORY (attr->fMode);
     85        is_dir = RTFS_IS_DIRECTORY(attr->fMode);
    8686
    8787#define mode_set(r) attr->fMode & (RTFS_UNIX_##r) ? (S_##r) : 0;
    88         mode = mode_set (ISUID);
    89         mode |= mode_set (ISGID);
    90 
    91         mode |= mode_set (IRUSR);
    92         mode |= mode_set (IWUSR);
    93         mode |= mode_set (IXUSR);
    94 
    95         mode |= mode_set (IRGRP);
    96         mode |= mode_set (IWGRP);
    97         mode |= mode_set (IXGRP);
    98 
    99         mode |= mode_set (IROTH);
    100         mode |= mode_set (IWOTH);
    101         mode |= mode_set (IXOTH);
     88        mode = mode_set(ISUID);
     89        mode |= mode_set(ISGID);
     90
     91        mode |= mode_set(IRUSR);
     92        mode |= mode_set(IWUSR);
     93        mode |= mode_set(IXUSR);
     94
     95        mode |= mode_set(IRGRP);
     96        mode |= mode_set(IWGRP);
     97        mode |= mode_set(IXGRP);
     98
     99        mode |= mode_set(IROTH);
     100        mode |= mode_set(IWOTH);
     101        mode |= mode_set(IXOTH);
    102102#undef mode_set
    103103
    104 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     104#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    105105        inode->i_mapping->a_ops = &sf_reg_aops;
    106106        inode->i_mapping->backing_dev_info = &sf_g->bdi;
     
    129129        inode->i_gid = sf_g->gid;
    130130        inode->i_size = info->cbObject;
    131 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 19) && !defined(KERNEL_FC6)
     131#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) && !defined(KERNEL_FC6)
    132132        inode->i_blksize = 4096;
    133133#endif
    134 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 11)
     134#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 11)
    135135        inode->i_blkbits = 12;
    136136#endif
     
    138138        inode->i_blocks = (info->cbAllocated + 511) / 512;
    139139
    140         sf_ftime_from_timespec (&inode->i_atime, &info->AccessTime);
    141         sf_ftime_from_timespec (&inode->i_ctime, &info->ChangeTime);
    142         sf_ftime_from_timespec (&inode->i_mtime, &info->ModificationTime);
     140        sf_ftime_from_timespec(&inode->i_atime, &info->AccessTime);
     141        sf_ftime_from_timespec(&inode->i_ctime, &info->ChangeTime);
     142        sf_ftime_from_timespec(&inode->i_mtime, &info->ModificationTime);
    143143}
    144144
    145145int
    146 sf_stat (const char *caller, struct sf_glob_info *sf_g,
    147          SHFLSTRING *path, RTFSOBJINFO *result, int ok_to_fail)
     146sf_stat(const char *caller, struct sf_glob_info *sf_g,
     147        SHFLSTRING *path, RTFSOBJINFO *result, int ok_to_fail)
    148148{
    149149        int rc;
    150150        SHFLCREATEPARMS params;
    151151
    152         TRACE ();
     152        TRACE();
    153153
    154154        RT_ZERO(params);
     
    156156        LogFunc(("sf_stat: calling vboxCallCreate, file %s, flags %#x\n",
    157157                 path->String.utf8, params.CreateFlags));
    158         rc = vboxCallCreate (&client_handle, &sf_g->map, path, &params);
    159         if (RT_FAILURE (rc)) {
     158        rc = vboxCallCreate(&client_handle, &sf_g->map, path, &params);
     159        if (RT_FAILURE(rc)) {
    160160                LogFunc(("vboxCallCreate(%s) failed.  caller=%s, rc=%Rrc\n",
    161161                         path->String.utf8, rc, caller));
     
    182182   update inode attributes */
    183183int
    184 sf_inode_revalidate (struct dentry *dentry)
     184sf_inode_revalidate(struct dentry *dentry)
    185185{
    186186        int err;
     
    189189        RTFSOBJINFO info;
    190190
    191         TRACE ();
     191        TRACE();
    192192        if (!dentry || !dentry->d_inode) {
    193193                LogFunc(("no dentry(%p) or inode(%p)\n", dentry, dentry->d_inode));
     
    195195        }
    196196
    197         sf_g = GET_GLOB_INFO (dentry->d_inode->i_sb);
    198         sf_i = GET_INODE_INFO (dentry->d_inode);
     197        sf_g = GET_GLOB_INFO(dentry->d_inode->i_sb);
     198        sf_i = GET_INODE_INFO(dentry->d_inode);
    199199
    200200#if 0
    201         printk ("%s called by %p:%p\n",
    202                 sf_i->path->String.utf8,
    203                 __builtin_return_address (0),
    204                 __builtin_return_address (1));
    205 #endif
    206 
    207         BUG_ON (!sf_g);
    208         BUG_ON (!sf_i);
     201        printk("%s called by %p:%p\n",
     202               sf_i->path->String.utf8,
     203               __builtin_return_address (0),
     204               __builtin_return_address (1));
     205#endif
     206
     207        BUG_ON(!sf_g);
     208        BUG_ON(!sf_i);
    209209
    210210        if (!sf_i->force_restat) {
     
    214214        }
    215215
    216         err = sf_stat (__func__, sf_g, sf_i->path, &info, 1);
     216        err = sf_stat(__func__, sf_g, sf_i->path, &info, 1);
    217217        if (err) {
    218218                return err;
     
    220220
    221221        dentry->d_time = jiffies;
    222         sf_init_inode (sf_g, dentry->d_inode, &info);
     222        sf_init_inode(sf_g, dentry->d_inode, &info);
    223223        return 0;
    224224}
     
    228228   [sf_inode_revalidate] */
    229229static int
    230 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
    231 sf_dentry_revalidate (struct dentry *dentry, int flags)
     230#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
     231sf_dentry_revalidate(struct dentry *dentry, int flags)
    232232#else
    233 sf_dentry_revalidate (struct dentry *dentry, struct nameidata *nd)
    234 #endif
    235 {
    236         TRACE ();
    237         if (sf_inode_revalidate (dentry)) {
     233sf_dentry_revalidate(struct dentry *dentry, struct nameidata *nd)
     234#endif
     235{
     236        TRACE();
     237        if (sf_inode_revalidate(dentry)) {
    238238                return 0;
    239239        }
     
    245245   has inode at all) from these new attributes we derive [kstat] via
    246246   [generic_fillattr] */
    247 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     247#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    248248int
    249 sf_getattr (struct vfsmount *mnt, struct dentry *dentry, struct kstat *kstat)
     249sf_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *kstat)
    250250{
    251251        int err;
    252252
    253         TRACE ();
    254         err = sf_inode_revalidate (dentry);
     253        TRACE();
     254        err = sf_inode_revalidate(dentry);
    255255        if (err) {
    256256                return err;
    257257        }
    258258
    259         generic_fillattr (dentry->d_inode, kstat);
     259        generic_fillattr(dentry->d_inode, kstat);
    260260        return 0;
    261261}
    262262
    263263int
    264 sf_setattr (struct dentry *dentry, struct iattr *iattr)
     264sf_setattr(struct dentry *dentry, struct iattr *iattr)
    265265{
    266266        struct sf_glob_info *sf_g;
     
    271271        int rc, err;
    272272
    273         TRACE ();
    274 
    275         sf_g = GET_GLOB_INFO (dentry->d_inode->i_sb);
    276         sf_i = GET_INODE_INFO (dentry->d_inode);
     273        TRACE();
     274
     275        sf_g = GET_GLOB_INFO(dentry->d_inode->i_sb);
     276        sf_i = GET_INODE_INFO(dentry->d_inode);
    277277        err  = 0;
    278278
     
    287287            params.CreateFlags |= SHFL_CF_ACCESS_WRITE;
    288288
    289         rc = vboxCallCreate (&client_handle, &sf_g->map, sf_i->path, &params);
    290         if (RT_FAILURE (rc)) {
     289        rc = vboxCallCreate(&client_handle, &sf_g->map, sf_i->path, &params);
     290        if (RT_FAILURE(rc)) {
    291291                LogFunc(("vboxCallCreate(%s) failed rc=%Rrc\n",
    292292                        sf_i->path->String.utf8, rc));
     
    310310            if (iattr->ia_valid & ATTR_MODE)
    311311            {
    312                 info.Attr.fMode  = mode_set (ISUID);
    313                 info.Attr.fMode |= mode_set (ISGID);
    314                 info.Attr.fMode |= mode_set (IRUSR);
    315                 info.Attr.fMode |= mode_set (IWUSR);
    316                 info.Attr.fMode |= mode_set (IXUSR);
    317                 info.Attr.fMode |= mode_set (IRGRP);
    318                 info.Attr.fMode |= mode_set (IWGRP);
    319                 info.Attr.fMode |= mode_set (IXGRP);
    320                 info.Attr.fMode |= mode_set (IROTH);
    321                 info.Attr.fMode |= mode_set (IWOTH);
    322                 info.Attr.fMode |= mode_set (IXOTH);
     312                info.Attr.fMode  = mode_set(ISUID);
     313                info.Attr.fMode |= mode_set(ISGID);
     314                info.Attr.fMode |= mode_set(IRUSR);
     315                info.Attr.fMode |= mode_set(IWUSR);
     316                info.Attr.fMode |= mode_set(IXUSR);
     317                info.Attr.fMode |= mode_set(IRGRP);
     318                info.Attr.fMode |= mode_set(IWGRP);
     319                info.Attr.fMode |= mode_set(IXGRP);
     320                info.Attr.fMode |= mode_set(IROTH);
     321                info.Attr.fMode |= mode_set(IWOTH);
     322                info.Attr.fMode |= mode_set(IXOTH);
    323323
    324324                if (iattr->ia_mode & S_IFDIR)
     
    329329
    330330            if (iattr->ia_valid & ATTR_ATIME)
    331                 sf_timespec_from_ftime (&info.AccessTime, &iattr->ia_atime);
     331                sf_timespec_from_ftime(&info.AccessTime, &iattr->ia_atime);
    332332            if (iattr->ia_valid & ATTR_MTIME)
    333                 sf_timespec_from_ftime (&info.ModificationTime, &iattr->ia_mtime);
     333                sf_timespec_from_ftime(&info.ModificationTime, &iattr->ia_mtime);
    334334            /* ignore ctime (inode change time) as it can't be set from userland anyway */
    335335
     
    338338                                SHFL_INFO_SET | SHFL_INFO_FILE, &cbBuffer,
    339339                                (PSHFLDIRINFO)&info);
    340             if (RT_FAILURE (rc)) {
     340            if (RT_FAILURE(rc)) {
    341341                LogFunc(("vboxCallFSInfo(%s, FILE) failed rc=%Rrc\n",
    342342                        sf_i->path->String.utf8, rc));
     
    354354                                SHFL_INFO_SET | SHFL_INFO_SIZE, &cbBuffer,
    355355                                (PSHFLDIRINFO)&info);
    356             if (RT_FAILURE (rc)) {
     356            if (RT_FAILURE(rc)) {
    357357                LogFunc(("vboxCallFSInfo(%s, SIZE) failed rc=%Rrc\n",
    358358                        sf_i->path->String.utf8, rc));
     
    362362        }
    363363
    364         rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    365         if (RT_FAILURE (rc))
     364        rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     365        if (RT_FAILURE(rc))
    366366        {
    367367                LogFunc(("vboxCallClose(%s) failed rc=%Rrc\n",
     
    369369        }
    370370
    371         return sf_inode_revalidate (dentry);
     371        return sf_inode_revalidate(dentry);
    372372
    373373fail1:
    374         rc = vboxCallClose (&client_handle, &sf_g->map, params.Handle);
    375         if (RT_FAILURE (rc))
     374        rc = vboxCallClose(&client_handle, &sf_g->map, params.Handle);
     375        if (RT_FAILURE(rc))
    376376        {
    377377                LogFunc(("vboxCallClose(%s) failed rc=%Rrc\n",
     
    384384
    385385static int
    386 sf_make_path (const char *caller, struct sf_inode_info *sf_i,
     386sf_make_path(const char *caller, struct sf_inode_info *sf_i,
    387387              const char *d_name, size_t d_len, SHFLSTRING **result)
    388388{
     
    394394        int is_root = 0;
    395395
    396         TRACE ();
     396        TRACE();
    397397        p_len = sf_i->path->u16Length;
    398398        p_name = sf_i->path->String.utf8;
     
    411411        }
    412412
    413         shflstring_len = offsetof (SHFLSTRING, String.utf8) + path_len;
    414         tmp = kmalloc (shflstring_len, GFP_KERNEL);
     413        shflstring_len = offsetof(SHFLSTRING, String.utf8) + path_len;
     414        tmp = kmalloc(shflstring_len, GFP_KERNEL);
    415415        if (!tmp) {
    416416                LogRelFunc(("kmalloc failed, caller=%s\n", caller));
     
    421421
    422422        if (is_root) {
    423                 memcpy (tmp->String.utf8, d_name, d_len + 1);
     423                memcpy(tmp->String.utf8, d_name, d_len + 1);
    424424        }
    425425        else {
    426426                dst = tmp->String.utf8;
    427                 memcpy (dst, p_name, p_len);
     427                memcpy(dst, p_name, p_len);
    428428                dst += p_len; *dst++ = '/';
    429                 memcpy (dst, d_name, d_len);
     429                memcpy(dst, d_name, d_len);
    430430                dst[d_len] = 0;
    431431        }
     
    439439   [sf_make_path] which will allocate SHFLSTRING and fill it in */
    440440int
    441 sf_path_from_dentry (const char *caller, struct sf_glob_info *sf_g,
     441sf_path_from_dentry(const char *caller, struct sf_glob_info *sf_g,
    442442                     struct sf_inode_info *sf_i, struct dentry *dentry,
    443443                     SHFLSTRING **result)
     
    449449        size_t len = 0;
    450450
    451         TRACE ();
     451        TRACE();
    452452        d_name = dentry->d_name.name;
    453453        d_len = dentry->d_name.len;
     
    462462
    463463                out_bound_len = PATH_MAX;
    464                 out = kmalloc (out_bound_len, GFP_KERNEL);
     464                out = kmalloc(out_bound_len, GFP_KERNEL);
    465465                name = out;
    466466
     
    471471                        int nb;
    472472
    473                         nb = sf_g->nls->char2uni (in, in_len, &uni);
     473                        nb = sf_g->nls->char2uni(in, in_len, &uni);
    474474                        if (nb < 0) {
    475475                                LogFunc(("nls->char2uni failed %x %d\n",
     
    481481                        in += nb;
    482482
    483 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 31)
    484                         nb = utf32_to_utf8 (uni, out, out_bound_len);
     483#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
     484                        nb = utf32_to_utf8(uni, out, out_bound_len);
    485485#else
    486                         nb = utf8_wctomb (out, uni, out_bound_len);
     486                        nb = utf8_wctomb(out, uni, out_bound_len);
    487487#endif
    488488                        if (nb < 0) {
     
    509509        }
    510510
    511         err = sf_make_path (caller, sf_i, name, len, result);
     511        err = sf_make_path(caller, sf_i, name, len, result);
    512512        if (name != d_name) {
    513                 kfree (name);
     513                kfree(name);
    514514        }
    515515        return err;
    516516
    517517 fail1:
    518         kfree (name);
     518        kfree(name);
    519519        return err;
    520520}
    521521
    522522int
    523 sf_nlscpy (struct sf_glob_info *sf_g,
     523sf_nlscpy(struct sf_glob_info *sf_g,
    524524           char *name, size_t name_bound_len,
    525525           const unsigned char *utf8_name, size_t utf8_len)
     
    543543                        wchar_t uni;
    544544
    545 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 31)
    546                         nb = utf8_to_utf32 (in, in_bound_len, &uni);
     545#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
     546                        nb = utf8_to_utf32(in, in_bound_len, &uni);
    547547#else
    548                         nb = utf8_mbtowc (&uni, in, in_bound_len);
     548                        nb = utf8_mbtowc(&uni, in, in_bound_len);
    549549#endif
    550550                        if (nb < 0) {
     
    556556                        in_bound_len -= nb;
    557557
    558                         nb = sf_g->nls->uni2char (uni, out, out_bound_len);
     558                        nb = sf_g->nls->uni2char(uni, out, out_bound_len);
    559559                        if (nb < 0) {
    560560                                LogFunc(("nls->uni2char failed(%s) %x:%d\n",
     
    575575                }
    576576                else {
    577                         memcpy (name, utf8_name, utf8_len + 1);
     577                        memcpy(name, utf8_name, utf8_len + 1);
    578578                }
    579579                return 0;
     
    582582
    583583static struct sf_dir_buf *
    584 sf_dir_buf_alloc (void)
     584sf_dir_buf_alloc(void)
    585585{
    586586        struct sf_dir_buf *b;
    587587
    588         TRACE ();
    589         b = kmalloc (sizeof (*b), GFP_KERNEL);
     588        TRACE();
     589        b = kmalloc(sizeof(*b), GFP_KERNEL);
    590590        if (!b) {
    591591                LogRelFunc(("could not alloc directory buffer\n"));
     
    594594
    595595#ifdef USE_VMALLOC
    596         b->buf = vmalloc (16384);
     596        b->buf = vmalloc(16384);
    597597#else
    598         b->buf = kmalloc (16384, GFP_KERNEL);
     598        b->buf = kmalloc(16384, GFP_KERNEL);
    599599#endif
    600600        if (!b->buf) {
    601                 kfree (b);
     601                kfree(b);
    602602                LogRelFunc(("could not alloc directory buffer storage\n"));
    603603                return NULL;
    604604        }
    605605
    606         INIT_LIST_HEAD (&b->head);
     606        INIT_LIST_HEAD(&b->head);
    607607        b->nb_entries = 0;
    608608        b->used_bytes = 0;
     
    612612
    613613static void
    614 sf_dir_buf_free (struct sf_dir_buf *b)
    615 {
    616         BUG_ON (!b || !b->buf);
    617 
    618         TRACE ();
    619         list_del (&b->head);
     614sf_dir_buf_free(struct sf_dir_buf *b)
     615{
     616        BUG_ON(!b || !b->buf);
     617
     618        TRACE();
     619        list_del(&b->head);
    620620#ifdef USE_VMALLOC
    621         vfree (b->buf);
     621        vfree(b->buf);
    622622#else
    623         kfree (b->buf);
    624 #endif
    625         kfree (b);
     623        kfree(b->buf);
     624#endif
     625        kfree(b);
    626626}
    627627
    628628void
    629 sf_dir_info_free (struct sf_dir_info *p)
     629sf_dir_info_free(struct sf_dir_info *p)
    630630{
    631631        struct list_head *list, *pos, *tmp;
    632632
    633         TRACE ();
     633        TRACE();
    634634        list = &p->info_list;
    635         list_for_each_safe (pos, tmp, list) {
     635        list_for_each_safe(pos, tmp, list) {
    636636                struct sf_dir_buf *b;
    637637
    638                 b = list_entry (pos, struct sf_dir_buf, head);
    639                 sf_dir_buf_free (b);
    640         }
    641         kfree (p);
     638                b = list_entry(pos, struct sf_dir_buf, head);
     639                sf_dir_buf_free(b);
     640        }
     641        kfree(p);
    642642}
    643643
     
    646646{
    647647        struct list_head *list, *pos, *tmp;
    648         TRACE ();
     648        TRACE();
    649649        list = &p->info_list;
    650         list_for_each_safe (pos, tmp, list) {
     650        list_for_each_safe(pos, tmp, list) {
    651651                struct sf_dir_buf *b;
    652                 b = list_entry (pos, struct sf_dir_buf, head);
     652                b = list_entry(pos, struct sf_dir_buf, head);
    653653                b->nb_entries = 0;
    654654                b->used_bytes = 0;
     
    658658
    659659struct sf_dir_info *
    660 sf_dir_info_alloc (void)
     660sf_dir_info_alloc(void)
    661661{
    662662        struct sf_dir_info *p;
    663663
    664         TRACE ();
    665         p = kmalloc (sizeof (*p), GFP_KERNEL);
     664        TRACE();
     665        p = kmalloc(sizeof(*p), GFP_KERNEL);
    666666        if (!p) {
    667667                LogRelFunc(("could not alloc directory info\n"));
     
    669669        }
    670670
    671         INIT_LIST_HEAD (&p->info_list);
     671        INIT_LIST_HEAD(&p->info_list);
    672672        return p;
    673673}
    674674
    675675static struct sf_dir_buf *
    676 sf_get_empty_dir_buf (struct sf_dir_info *sf_d)
     676sf_get_empty_dir_buf(struct sf_dir_info *sf_d)
    677677{
    678678        struct list_head *list, *pos;
    679679
    680680        list = &sf_d->info_list;
    681         list_for_each (pos, list) {
     681        list_for_each(pos, list) {
    682682                struct sf_dir_buf *b;
    683683
    684                 b = list_entry (pos, struct sf_dir_buf, head);
     684                b = list_entry(pos, struct sf_dir_buf, head);
    685685                if (!b) {
    686686                        return NULL;
     
    697697
    698698int
    699 sf_dir_read_all (struct sf_glob_info *sf_g, struct sf_inode_info *sf_i,
     699sf_dir_read_all(struct sf_glob_info *sf_g, struct sf_inode_info *sf_i,
    700700                 struct sf_dir_info *sf_d, SHFLHANDLE handle)
    701701{
     
    704704        struct sf_dir_buf *b;
    705705
    706         TRACE ();
    707         err = sf_make_path (__func__, sf_i, "*", 1, &mask);
     706        TRACE();
     707        err = sf_make_path(__func__, sf_i, "*", 1, &mask);
    708708        if (err) {
    709709                goto fail0;
     
    716716                uint32_t nb_ents;
    717717
    718                 b = sf_get_empty_dir_buf (sf_d);
     718                b = sf_get_empty_dir_buf(sf_d);
    719719                if (!b) {
    720                         b = sf_dir_buf_alloc ();
     720                        b = sf_dir_buf_alloc();
    721721                        if (!b) {
    722722                                err = -ENOMEM;
     
    724724                                goto fail1;
    725725                        }
    726                         list_add (&b->head, &sf_d->info_list);
     726                        list_add(&b->head, &sf_d->info_list);
    727727                }
    728728
     
    730730                buf_size = b->free_bytes;
    731731
    732                 rc = vboxCallDirInfo (
    733                         &client_handle,
    734                         &sf_g->map,
    735                         handle,
    736                         mask,
    737                         0,
    738                         0,
    739                         &buf_size,
    740                         buf,
    741                         &nb_ents
    742                         );
     732                rc = vboxCallDirInfo(&client_handle, &sf_g->map, handle, mask,
     733                                     0, 0, &buf_size, buf, &nb_ents);
    743734                switch (rc) {
    744735                        case VINF_SUCCESS:
     
    753744
    754745                        default:
    755                                 err = -RTErrConvertToErrno (rc);
     746                                err = -RTErrConvertToErrno(rc);
    756747                                LogFunc(("vboxCallDirInfo failed rc=%Rrc\n", rc));
    757748                                goto fail1;
     
    762753                b->used_bytes += buf_size;
    763754
    764                 if (RT_FAILURE (rc))
     755                if (RT_FAILURE(rc))
    765756                        break;
    766757        }
     
    768759
    769760 fail1:
    770         kfree (mask);
     761        kfree(mask);
    771762 fail0:
    772763        return err;
     
    780771        int rc;
    781772
    782         sf_g = GET_GLOB_INFO (sb);
     773        sf_g = GET_GLOB_INFO(sb);
    783774        cbBuffer = sizeof(SHFLVolumeInfo);
    784775        rc = vboxCallFSInfo(&client_handle, &sf_g->map, 0, SHFL_INFO_GET | SHFL_INFO_VOLUME,
     
    812803    int rc = 0;
    813804
    814 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 0)
     805#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    815806    sf_g->bdi.ra_pages = 0; /* No readahead */
    816 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 12)
     807# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 12)
    817808    sf_g->bdi.capabilities  = BDI_CAP_MAP_DIRECT    /* MAP_SHARED */
    818809                            | BDI_CAP_MAP_COPY      /* MAP_PRIVATE */
     
    821812                            | BDI_CAP_EXEC_MAP;     /* can be mapped for execution */
    822813# endif /* >= 2.6.12 */
    823 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24)
     814# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
    824815    rc = bdi_init(&sf_g->bdi);
    825 #  if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 26)
     816#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
    826817    if (!rc)
    827818        rc = bdi_register(&sf_g->bdi, NULL, "vboxsf-%s", name);
     
    834825void sf_done_backing_dev(struct sf_glob_info *sf_g)
    835826{
    836 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24)
     827#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
    837828    bdi_destroy(&sf_g->bdi); /* includes bdi_unregister() */
    838829#endif
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c

    r28998 r30153  
    4343// #define wchar_t linux_wchar_t
    4444
    45 MODULE_DESCRIPTION (VBOX_PRODUCT " VFS Module for Host File System Access");
    46 MODULE_AUTHOR (VBOX_VENDOR);
    47 MODULE_LICENSE ("GPL");
     45MODULE_DESCRIPTION(VBOX_PRODUCT " VFS Module for Host File System Access");
     46MODULE_AUTHOR(VBOX_VENDOR);
     47MODULE_LICENSE("GPL");
    4848#ifdef MODULE_VERSION
    4949MODULE_VERSION(VBOX_VERSION_STRING " (interface " RT_XSTR(VMMDEV_VERSION) ")");
     
    6262/* allocate global info, try to map host share */
    6363static int
    64 sf_glob_alloc (struct vbsf_mount_info_new *info, struct sf_glob_info **sf_gp)
     64sf_glob_alloc(struct vbsf_mount_info_new *info, struct sf_glob_info **sf_gp)
    6565{
    6666        int err, rc;
     
    6969        struct sf_glob_info *sf_g;
    7070
    71         TRACE ();
    72         sf_g = kmalloc (sizeof (*sf_g), GFP_KERNEL);
     71        TRACE();
     72        sf_g = kmalloc(sizeof(*sf_g), GFP_KERNEL);
    7373        if (!sf_g) {
    7474                err = -ENOMEM;
     
    9999        }
    100100
    101         info->name[sizeof (info->name) - 1] = 0;
    102         info->nls_name[sizeof (info->nls_name) - 1] = 0;
    103 
    104         name_len = strlen (info->name);
     101        info->name[sizeof(info->name) - 1] = 0;
     102        info->nls_name[sizeof(info->nls_name) - 1] = 0;
     103
     104        name_len = strlen(info->name);
    105105        if (name_len > 0xfffe) {
    106106                err = -ENAMETOOLONG;
     
    109109        }
    110110
    111         str_len = offsetof (SHFLSTRING, String.utf8) + name_len + 1;
    112         str_name = kmalloc (str_len, GFP_KERNEL);
     111        str_len = offsetof(SHFLSTRING, String.utf8) + name_len + 1;
     112        str_name = kmalloc(str_len, GFP_KERNEL);
    113113        if (!str_name) {
    114114                err = -ENOMEM;
     
    119119        str_name->u16Length = name_len;
    120120        str_name->u16Size = name_len + 1;
    121         memcpy (str_name->String.utf8, info->name, name_len + 1);
    122 
    123         if (info->nls_name[0] && strcmp (info->nls_name, "utf8")) {
    124                 sf_g->nls = load_nls (info->nls_name);
     121        memcpy(str_name->String.utf8, info->name, name_len + 1);
     122
     123        if (info->nls_name[0] && strcmp(info->nls_name, "utf8")) {
     124                sf_g->nls = load_nls(info->nls_name);
    125125                if (!sf_g->nls) {
    126126                        err = -EINVAL;
     
    133133        }
    134134
    135         rc = vboxCallMapFolder (&client_handle, str_name, &sf_g->map);
    136         kfree (str_name);
    137 
    138         if (RT_FAILURE (rc)) {
     135        rc = vboxCallMapFolder(&client_handle, str_name, &sf_g->map);
     136        kfree(str_name);
     137
     138        if (RT_FAILURE(rc)) {
    139139                err = -EPROTO;
    140140                LogFunc(("vboxCallMapFolder failed rc=%d\n", rc));
     
    165165 fail2:
    166166        if (sf_g->nls) {
    167                 unload_nls (sf_g->nls);
     167                unload_nls(sf_g->nls);
    168168        }
    169169 fail1:
    170         kfree (sf_g);
     170        kfree(sf_g);
    171171 fail0:
    172172        return err;
     
    175175/* unmap the share and free global info [sf_g] */
    176176static void
    177 sf_glob_free (struct sf_glob_info *sf_g)
     177sf_glob_free(struct sf_glob_info *sf_g)
    178178{
    179179        int rc;
    180180
    181         TRACE ();
    182         rc = vboxCallUnmapFolder (&client_handle, &sf_g->map);
    183         if (RT_FAILURE (rc)) {
     181        TRACE();
     182        rc = vboxCallUnmapFolder(&client_handle, &sf_g->map);
     183        if (RT_FAILURE(rc)) {
    184184                LogFunc(("vboxCallUnmapFolder failed rc=%d\n", rc));
    185185        }
    186186
    187187        if (sf_g->nls) {
    188                 unload_nls (sf_g->nls);
    189         }
    190         kfree (sf_g);
     188                unload_nls(sf_g->nls);
     189        }
     190        kfree(sf_g);
    191191}
    192192
     
    201201   should respect [flags] */
    202202static int
    203 sf_read_super_aux (struct super_block *sb, void *data, int flags)
     203sf_read_super_aux(struct super_block *sb, void *data, int flags)
    204204{
    205205        int err;
     
    211211        struct vbsf_mount_info_new *info;
    212212
    213         TRACE ();
     213        TRACE();
    214214        if (!data) {
    215215                LogFunc(("no mount info specified\n"));
     
    224224        }
    225225
    226         err = sf_glob_alloc (info, &sf_g);
     226        err = sf_glob_alloc(info, &sf_g);
    227227        if (err) {
    228228                goto fail0;
    229229        }
    230230
    231         sf_i = kmalloc (sizeof (*sf_i), GFP_KERNEL);
     231        sf_i = kmalloc(sizeof (*sf_i), GFP_KERNEL);
    232232        if (!sf_i) {
    233233                err = -ENOMEM;
    234                 LogRelFunc (("could not allocate memory for root inode info\n"));
     234                LogRelFunc(("could not allocate memory for root inode info\n"));
    235235                goto fail1;
    236236        }
    237237
    238238        sf_i->handle = SHFL_HANDLE_NIL;
    239         sf_i->path = kmalloc (sizeof (SHFLSTRING) + 1, GFP_KERNEL);
     239        sf_i->path = kmalloc(sizeof(SHFLSTRING) + 1, GFP_KERNEL);
    240240        if (!sf_i->path) {
    241241                err = -ENOMEM;
    242                 LogRelFunc (("could not allocate memory for root inode path\n"));
     242                LogRelFunc(("could not allocate memory for root inode path\n"));
    243243                goto fail2;
    244244        }
     
    249249        sf_i->path->String.utf8[1] = 0;
    250250
    251         err = sf_stat (__func__, sf_g, sf_i->path, &fsinfo, 0);
     251        err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0);
    252252        if (err) {
    253253                LogFunc(("could not stat root of share\n"));
     
    257257        sb->s_magic = 0xface;
    258258        sb->s_blocksize = 1024;
    259 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 3)
     259#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 3)
    260260        /* Required for seek/sendfile.
    261261         *
     
    273273        sb->s_op = &sf_super_ops;
    274274
    275 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
    276         iroot = iget_locked (sb, 0);
     275#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
     276        iroot = iget_locked(sb, 0);
    277277#else
    278         iroot = iget (sb, 0);
     278        iroot = iget(sb, 0);
    279279#endif
    280280        if (!iroot) {
     
    290290        }
    291291
    292         sf_init_inode (sf_g, iroot, &fsinfo);
    293         SET_INODE_INFO (iroot, sf_i);
    294 
    295 #if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 4, 25)
     292        sf_init_inode(sf_g, iroot, &fsinfo);
     293        SET_INODE_INFO(iroot, sf_i);
     294
     295#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25)
    296296        unlock_new_inode(iroot);
    297297#endif
    298298
    299         droot = d_alloc_root (iroot);
     299        droot = d_alloc_root(iroot);
    300300        if (!droot) {
    301301                err = -ENOMEM;  /* XXX */
     
    305305
    306306        sb->s_root = droot;
    307         SET_GLOB_INFO (sb, sf_g);
     307        SET_GLOB_INFO(sb, sf_g);
    308308        return 0;
    309309
     
    311311        sf_done_backing_dev(sf_g);
    312312 fail4:
    313         iput (iroot);
     313        iput(iroot);
    314314 fail3:
    315         kfree (sf_i->path);
     315        kfree(sf_i->path);
    316316 fail2:
    317         kfree (sf_i);
     317        kfree(sf_i);
    318318 fail1:
    319         sf_glob_free (sf_g);
     319        sf_glob_free(sf_g);
    320320 fail0:
    321321        return err;
    322322}
    323323
    324 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
     324#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    325325static struct super_block *
    326 sf_read_super_24 (struct super_block *sb, void *data, int flags)
     326sf_read_super_24(struct super_block *sb, void *data, int flags)
    327327{
    328328        int err;
    329329
    330         TRACE ();
    331         err = sf_read_super_aux (sb, data, flags);
     330        TRACE();
     331        err = sf_read_super_aux(sb, data, flags);
    332332        if (err) {
    333333                return NULL;
     
    341341   resources associated with this [inode] must be cleared here */
    342342static void
    343 sf_clear_inode (struct inode *inode)
     343sf_clear_inode(struct inode *inode)
    344344{
    345345        struct sf_inode_info *sf_i;
    346346
    347         TRACE ();
    348         sf_i = GET_INODE_INFO (inode);
     347        TRACE();
     348        sf_i = GET_INODE_INFO(inode);
    349349        if (!sf_i) {
    350350                return;
    351351        }
    352352
    353         BUG_ON (!sf_i->path);
    354         kfree (sf_i->path);
    355         kfree (sf_i);
    356         SET_INODE_INFO (inode, NULL);
     353        BUG_ON(!sf_i->path);
     354        kfree(sf_i->path);
     355        kfree(sf_i);
     356        SET_INODE_INFO(inode, NULL);
    357357}
    358358
     
    361361   hence we can't do anything here, and let lookup/whatever with the
    362362   job to properly fill then [inode] */
    363 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 25)
     363#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
    364364static void
    365 sf_read_inode (struct inode *inode)
     365sf_read_inode(struct inode *inode)
    366366{
    367367}
     
    371371   the folder and free [sf_g] */
    372372static void
    373 sf_put_super (struct super_block *sb)
     373sf_put_super(struct super_block *sb)
    374374{
    375375        struct sf_glob_info *sf_g;
    376376
    377         sf_g = GET_GLOB_INFO (sb);
    378         BUG_ON (!sf_g);
     377        sf_g = GET_GLOB_INFO(sb);
     378        BUG_ON(!sf_g);
    379379        sf_done_backing_dev(sf_g);
    380         sf_glob_free (sf_g);
    381 }
    382 
    383 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 18)
    384 static int
    385 sf_statfs (struct super_block *sb, STRUCT_STATFS *stat)
     380        sf_glob_free(sf_g);
     381}
     382
     383#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
     384static int
     385sf_statfs(struct super_block *sb, STRUCT_STATFS *stat)
    386386{
    387387        return sf_get_volume_info(sb, stat);
     
    389389#else
    390390static int
    391 sf_statfs (struct dentry *dentry, STRUCT_STATFS *stat)
     391sf_statfs(struct dentry *dentry, STRUCT_STATFS *stat)
    392392{
    393393        struct super_block *sb = dentry->d_inode->i_sb;
     
    397397
    398398static int
    399 sf_remount_fs (struct super_block *sb, int *flags, char *data)
    400 {
    401         TRACE ();
     399sf_remount_fs(struct super_block *sb, int *flags, char *data)
     400{
     401        TRACE();
    402402        return -ENOSYS;
    403403}
     
    405405static struct super_operations sf_super_ops = {
    406406        .clear_inode = sf_clear_inode,
    407 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 25)
     407#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
    408408        .read_inode  = sf_read_inode,
    409409#endif
     
    413413};
    414414
    415 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 0)
    416 static DECLARE_FSTYPE (vboxsf_fs_type, "vboxsf", sf_read_super_24, 0);
     415#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
     416static DECLARE_FSTYPE(vboxsf_fs_type, "vboxsf", sf_read_super_24, 0);
    417417#else
    418418static int
    419 sf_read_super_26 (struct super_block *sb, void *data, int flags)
     419sf_read_super_26(struct super_block *sb, void *data, int flags)
    420420{
    421421        int err;
    422422
    423         TRACE ();
    424         err = sf_read_super_aux (sb, data, flags);
     423        TRACE();
     424        err = sf_read_super_aux(sb, data, flags);
    425425        if (err) {
    426                 printk (KERN_DEBUG "sf_read_super_aux err=%d\n", err);
     426                printk(KERN_DEBUG "sf_read_super_aux err=%d\n", err);
    427427        }
    428428        return err;
    429429}
    430430
    431 #if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 18)
     431#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
    432432static struct super_block *
    433 sf_get_sb (struct file_system_type *fs_type, int flags,
     433sf_get_sb(struct file_system_type *fs_type, int flags,
    434434           const char *dev_name, void *data)
    435435{
    436         TRACE ();
    437         return get_sb_nodev (fs_type, flags, data, sf_read_super_26);
     436        TRACE();
     437        return get_sb_nodev(fs_type, flags, data, sf_read_super_26);
    438438}
    439439#else
    440440static int
    441 sf_get_sb (struct file_system_type *fs_type, int flags,
     441sf_get_sb(struct file_system_type *fs_type, int flags,
    442442           const char *dev_name, void *data, struct vfsmount *mnt)
    443443{
    444         TRACE ();
    445         return get_sb_nodev (fs_type, flags, data, sf_read_super_26, mnt);
     444        TRACE();
     445        return get_sb_nodev(fs_type, flags, data, sf_read_super_26, mnt);
    446446}
    447447#endif
     
    457457/* Module initialization/finalization handlers */
    458458static int __init
    459 init (void)
     459init(void)
    460460{
    461461        int rcVBox;
     
    463463        int err;
    464464
    465         TRACE ();
    466 
    467         if (sizeof (struct vbsf_mount_info_new) > PAGE_SIZE) {
    468                 printk (KERN_ERR
    469                         "Mount information structure is too large %lu\n"
    470                         "Must be less than or equal to %lu\n",
    471                         (unsigned long)sizeof (struct vbsf_mount_info_new),
    472                         (unsigned long)PAGE_SIZE);
     465        TRACE();
     466
     467        if (sizeof(struct vbsf_mount_info_new) > PAGE_SIZE) {
     468                printk(KERN_ERR
     469                       "Mount information structure is too large %lu\n"
     470                       "Must be less than or equal to %lu\n",
     471                       (unsigned long)sizeof (struct vbsf_mount_info_new),
     472                       (unsigned long)PAGE_SIZE);
    473473                return -EINVAL;
    474474        }
    475475
    476         err = register_filesystem (&vboxsf_fs_type);
     476        err = register_filesystem(&vboxsf_fs_type);
    477477        if (err) {
    478478                LogFunc(("register_filesystem err=%d\n", err));
     
    480480        }
    481481
    482         rcVBox = vboxInit ();
    483         if (RT_FAILURE (rcVBox)) {
    484                 LogRelFunc (("vboxInit failed, rc=%d\n", rcVBox));
     482        rcVBox = vboxInit();
     483        if (RT_FAILURE(rcVBox)) {
     484                LogRelFunc(("vboxInit failed, rc=%d\n", rcVBox));
    485485                rcRet = -EPROTO;
    486486                goto fail0;
    487487        }
    488488
    489         rcVBox = vboxConnect (&client_handle);
    490         if (RT_FAILURE (rcVBox)) {
    491                 LogRelFunc (("vboxConnect failed, rc=%d\n", rcVBox));
     489        rcVBox = vboxConnect(&client_handle);
     490        if (RT_FAILURE(rcVBox)) {
     491                LogRelFunc(("vboxConnect failed, rc=%d\n", rcVBox));
    492492                rcRet = -EPROTO;
    493493                goto fail1;
    494494        }
    495495
    496         rcVBox = vboxCallSetUtf8 (&client_handle);
    497         if (RT_FAILURE (rcVBox)) {
    498                 LogRelFunc (("vboxCallSetUtf8 failed, rc=%d\n", rcVBox));
     496        rcVBox = vboxCallSetUtf8(&client_handle);
     497        if (RT_FAILURE(rcVBox)) {
     498                LogRelFunc(("vboxCallSetUtf8 failed, rc=%d\n", rcVBox));
    499499                rcRet = -EPROTO;
    500500                goto fail2;
     
    508508
    509509 fail2:
    510         vboxDisconnect (&client_handle);
     510        vboxDisconnect(&client_handle);
    511511 fail1:
    512         vboxUninit ();
     512        vboxUninit();
    513513 fail0:
    514         unregister_filesystem (&vboxsf_fs_type);
     514        unregister_filesystem(&vboxsf_fs_type);
    515515        return rcRet;
    516516}
    517517
    518518static void __exit
    519 fini (void)
    520 {
    521         TRACE ();
    522 
    523         vboxDisconnect (&client_handle);
    524         vboxUninit ();
    525         unregister_filesystem (&vboxsf_fs_type);
    526 }
    527 
    528 module_init (init);
    529 module_exit (fini);
     519fini(void)
     520{
     521        TRACE();
     522
     523        vboxDisconnect(&client_handle);
     524        vboxUninit();
     525        unregister_filesystem(&vboxsf_fs_type);
     526}
     527
     528module_init(init);
     529module_exit(fini);
    530530
    531531/* C++ hack */
    532532int __gxx_personality_v0 = 0xdeadbeef;
    533 
    534 #if 0
    535 /* long long hacks (as far as i can see, gcc emits the refs to those
    536    symbols, notwithstanding the fact that those aren't referenced
    537    anywhere in the module) */
    538 void __divdi3 (void)
    539 {
    540         elog ("called from %p\n", __builtin_return_address (0));
    541         BUG ();
    542 }
    543 
    544 void __moddi3 (void)
    545 {
    546         elog ("called from %p\n", __builtin_return_address (0));
    547         BUG ();
    548 }
    549 #endif /* 0 */
    550533
    551534/*
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.h

    r30150 r30153  
    8888extern struct address_space_operations sf_reg_aops;
    8989
    90 extern void
    91 sf_init_inode(struct sf_glob_info *sf_g, struct inode *inode,
    92               RTFSOBJINFO *info);
     90extern void sf_init_inode(struct sf_glob_info *sf_g, struct inode *inode,
     91                          RTFSOBJINFO *info);
    9392extern int sf_stat(const char *caller, struct sf_glob_info *sf_g,
    9493                   SHFLSTRING *path, RTFSOBJINFO *result, int ok_to_fail);
     
    114113
    115114#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    116 #define STRUCT_STATFS  struct statfs
     115# define STRUCT_STATFS  struct statfs
    117116#else
    118 #define STRUCT_STATFS  struct kstatfs
     117# define STRUCT_STATFS  struct kstatfs
    119118#endif
    120119int sf_get_volume_info(struct super_block *sb,STRUCT_STATFS *stat);
     
    126125#endif
    127126
    128 #define TRACE() LogFunc (("tracepoint\n"))
     127#define TRACE() LogFunc(("tracepoint\n"))
    129128
    130129/* Following casts are here to prevent assignment of void * to
    131130   pointers of arbitrary type */
    132131#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    133 #define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->u.generic_sbp)
    134 #define SET_GLOB_INFO(sb, sf_g) (sb)->u.generic_sbp = sf_g
     132# define GET_GLOB_INFO(sb)      ((struct sf_glob_info *) (sb)->u.generic_sbp)
     133# define SET_GLOB_INFO(sb, sf_g) (sb)->u.generic_sbp = sf_g
    135134#else
    136 #define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->s_fs_info)
    137 #define SET_GLOB_INFO(sb, sf_g) (sb)->s_fs_info = sf_g
     135# define GET_GLOB_INFO(sb)      ((struct sf_glob_info *) (sb)->s_fs_info)
     136# define SET_GLOB_INFO(sb, sf_g) (sb)->s_fs_info = sf_g
    138137#endif
    139138
    140139#if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 19) || defined(KERNEL_FC6)
    141140/* FC6 kernel 2.6.18, vanilla kernel 2.6.19+ */
    142 #define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->i_private)
    143 #define SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
     141# define GET_INODE_INFO(i)      ((struct sf_inode_info *) (i)->i_private)
     142# define SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
    144143#else
    145144/* vanilla kernel up to 2.6.18 */
    146 #define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->u.generic_ip)
    147 #define SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
     145# define GET_INODE_INFO(i)      ((struct sf_inode_info *) (i)->u.generic_ip)
     146# define SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
    148147#endif
    149148
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