VirtualBox

Changeset 11507 in vbox for trunk


Ignore:
Timestamp:
Aug 20, 2008 9:39:18 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
35028
Message:

Linux guest additions: allow to specify dmode, fmode, umask, dmask, fmask when mounting a shared folder. Note: read/write permissions currently not checked by vboxvfs.

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

Legend:

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

    r8155 r11507  
    118118   1       end reached
    119119   -errno  some form of error*/
    120 int
     120static int
    121121sf_getdent (struct file *dir, char d_name[NAME_MAX])
    122122{
  • trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c

    r8155 r11507  
    5858
    5959struct opts {
    60     int uid;
    61     int gid;
    62     int ttl;
    63     int ronly;
    64     int noexec;
    65     int nodev;
    66     int nosuid;
    67     int remount;
     60    int  uid;
     61    int  gid;
     62    int  ttl;
     63    int  dmode;
     64    int  fmode;
     65    int  dmask;
     66    int  fmask;
     67    int  ronly;
     68    int  noexec;
     69    int  nodev;
     70    int  nosuid;
     71    int  remount;
    6872    char nls_name[MAX_NLS_NAME];
    6973    char *convertcp;
     
    97101
    98102static int
    99 safe_atoi (const char *s, size_t size)
     103safe_atoi (const char *s, size_t size, int base)
    100104{
    101105    char *endptr;
    102     long long int val = strtoll (s, &endptr, 10);
     106    long long int val = strtoll (s, &endptr, base);
    103107
    104108    if (val < INT_MIN || val > INT_MAX || endptr < s + size) {
     
    122126        HOGID,
    123127        HOTTL,
     128        HODMODE,
     129        HOFMODE,
     130        HOUMASK,
     131        HODMASK,
     132        HOFMASK,
    124133        HOIOCHARSET,
    125134        HOCONVERTCP,
     
    145154        {"iocharset", HOIOCHARSET, 1, "i/o charset (default utf8)"},
    146155        {"convertcp", HOCONVERTCP, 1, "convert share name from given charset to utf8"},
     156        {"dmode",     HODMODE,     1, "mode of all directories"},
     157        {"fmode",     HOFMODE,     1, "mode of all regular files"},
     158        {"umask",     HOUMASK,     1, "umask of directories and regular files"},
     159        {"dmask",     HODMASK,     1, "umask of directories"},
     160        {"fmask",     HOFMASK,     1, "umask of regular files"},
    147161        {"noexec",    HONOEXEC,    0, 0 }, /* don't document these options directly here */
    148162        {"exec",      HOEXEC,      0, 0 }, /* as they are well known and described in the */
     
    227241                    break;
    228242                case HOUID:
    229                     opts->uid = safe_atoi (val, val_len);
     243                    opts->uid = safe_atoi (val, val_len, 10);
    230244                    break;
    231245                case HOGID:
    232                     opts->gid = safe_atoi (val, val_len);
     246                    opts->gid = safe_atoi (val, val_len, 10);
    233247                    break;
    234248                case HOTTL:
    235                     opts->ttl = safe_atoi (val, val_len);
     249                    opts->ttl = safe_atoi (val, val_len, 10);
     250                    break;
     251                case HODMODE:
     252                    opts->dmode = safe_atoi (val, val_len, 8);
     253                    break;
     254                case HOFMODE:
     255                    opts->fmode = safe_atoi (val, val_len, 8);
     256                    break;
     257                case HOUMASK:
     258                    opts->dmask = opts->fmask = safe_atoi (val, val_len, 8);
     259                    break;
     260                case HODMASK:
     261                    opts->dmask = safe_atoi (val, val_len, 8);
     262                    break;
     263                case HOFMASK:
     264                    opts->fmask = safe_atoi (val, val_len, 8);
    236265                    break;
    237266                case HOIOCHARSET:
     
    336365
    337366static void
    338 convertcp (char *in_codeset, char *host_name, struct vbsf_mount_info *info)
     367convertcp (char *in_codeset, char *host_name, struct vbsf_mount_info_new *info)
    339368{
    340369    char *i = host_name;
     
    373402           "  -w                    mount the shared folder writably (the default)\n"
    374403           "  -r                    mount the shared folder read-only\n"
    375            "  -n                    do not add information about the folder to the mtab file\n"
     404           "  -n                    do not create an mtab entry\n"
    376405           "  -o OPTION[,OPTION...] use the mount options specified\n"
    377406           "\n", name);
    378407    printf("Available mount options are:\n"
    379            "\n"
    380408           "     rw                 mount writably (the default)\n"
    381409           "     ro                 mount read only\n"
    382410           "     uid=UID            set the default file owner user id to UID\n"
    383411           "     gid=GID            set the default file owner group id to GID\n"
    384            "     ttl=TTL            set the \"time to live\" to TID for the dentry\n"
    385            "     iocharset CHARSET  use the character set CHARSET for i/o operations (default utf8)\n"
    386            "     convertcp CHARSET  convert the shared folder name from the character set CHARSET to utf8\n");
     412           "     ttl=TTL            set the \"time to live\" to TID for the dentry\n");
     413    printf("     dmode=MODE         override the mode of all directories to (octal) MODE\n"
     414           "     fmode=MODE         override the mode of all regular files to (octal) MODE\n"
     415           "     umask=UMASK        set the umask to (octal) UMASK\n");
     416    printf("     dmask=UMASK        set the umask applied to directories only\n"
     417           "     fmask=UMASK        set the umask applied to regular files only\n"
     418           "     iocharset CHARSET  use the character set CHARSET for I/O operations\n"
     419           "                        (default set is utf8)\n"
     420           "     convertcp CHARSET  convert the folder name from CHARSET to utf8\n"
     421           "\n");
    387422    printf("Less common used options:\n"
    388423           "     noexec,exec,nodev,dev,nosuid,suid\n");
     
    399434    char *host_name;
    400435    char *mount_point;
    401     struct vbsf_mount_info mntinf;
    402     struct opts opts = {
     436    struct vbsf_mount_info_new mntinf;
     437    struct opts opts =
     438    {
    403439        0,     /* uid */
    404440        0,     /* gid */
    405441        0,     /* ttl */
     442       ~0,     /* dmode */
     443       ~0,     /* fmode*/
     444        0,     /* dmask */
     445        0,     /* fmask */
    406446        0,     /* ronly */
    407447        0,     /* noexec */
     
    413453    };
    414454
     455    mntinf.nullchar = '\0';
     456    mntinf.signature[0] = VBSF_MOUNT_SIGNATURE_BYTE_0;
     457    mntinf.signature[1] = VBSF_MOUNT_SIGNATURE_BYTE_1;
     458    mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
     459
    415460    if (getuid ())
    416461        panic ("Only root can mount shared folders from the host.\n");
     
    476521        flags |= MS_NODEV;
    477522
    478     mntinf.uid = opts.uid;
    479     mntinf.gid = opts.gid;
    480     mntinf.ttl = opts.ttl;
     523    mntinf.uid   = opts.uid;
     524    mntinf.gid   = opts.gid;
     525    mntinf.ttl   = opts.ttl;
     526    mntinf.dmode = opts.dmode;
     527    mntinf.fmode = opts.fmode;
     528    mntinf.dmask = opts.dmask;
     529    mntinf.fmask = opts.fmask;
    481530
    482531    err = mount (NULL, mount_point, "vboxsf", flags, &mntinf);
     532    if (err == -1 && errno == EPROTO)
     533    {
     534        /* New mount tool with old vboxsf module? Try again using the old
     535         * vbsf_mount_info_old structure. */
     536        struct vbsf_mount_info_old mntinf_old;
     537        memcpy(&mntinf_old.name, &mntinf.name, MAX_HOST_NAME);
     538        memcpy(&mntinf_old.nls_name, mntinf.nls_name, MAX_NLS_NAME);
     539        mntinf_old.uid = mntinf.uid;
     540        mntinf_old.gid = mntinf.gid;
     541        mntinf_old.ttl = mntinf.ttl;
     542        err = mount (NULL, mount_point, "vboxsf", flags, &mntinf_old);
     543    }
    483544    if (err)
    484545        panic_err ("%s: mounting failed with the error", argv[0]);
  • trunk/src/VBox/Additions/linux/sharedfolders/regops.c

    r9179 r11507  
    6363        }
    6464
     65        /** XXX Check read permission accoring to inode->i_mode! */
     66
    6567        if (!size) {
    6668                return 0;
     
    133135        }
    134136
     137        /** XXX Check write permission accoring to inode->i_mode! */
     138
    135139        if (!size) {
    136140                return 0;
     
    139143        tmp = kmalloc (CHUNK_SIZE, GFP_KERNEL);
    140144        if (!tmp) {
    141                 LogRelFunc(("could not allocate bounce buffer memory %d\n", CHUNK_SIZE));
     145                LogRelFunc(("could not allocate bounce buffer memory %d bytes\n", CHUNK_SIZE));
    142146                return -ENOMEM;
    143147        }
  • trunk/src/VBox/Additions/linux/sharedfolders/utils.c

    r8155 r11507  
    111111
    112112        if (is_dir) {
    113                 inode->i_mode = S_IFDIR | mode;
    114                 inode->i_op = &sf_dir_iops;
    115                 inode->i_fop = &sf_dir_fops;
     113                inode->i_mode  = sf_g->dmode != ~0 ? (sf_g->dmode & 0777) : mode;
     114                inode->i_mode &= ~sf_g->dmask;
     115                inode->i_mode |= S_IFDIR;
     116                inode->i_op    = &sf_dir_iops;
     117                inode->i_fop   = &sf_dir_fops;
    116118                /* XXX: this probably should be set to the number of entries
    117119                   in the directory plus two (. ..) */
     
    119121        }
    120122        else {
    121                 inode->i_mode = S_IFREG | mode;
    122                 inode->i_op = &sf_reg_iops;
    123                 inode->i_fop = &sf_reg_fops;
     123                inode->i_mode  = sf_g->fmode != ~0 ? (sf_g->fmode & 0x777): mode;
     124                inode->i_mode &= ~sf_g->fmask;
     125                inode->i_mode |= S_IFREG;
     126                inode->i_op    = &sf_reg_iops;
     127                inode->i_fop   = &sf_reg_fops;
    124128                inode->i_nlink = 1;
    125129        }
  • trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h

    r8155 r11507  
    2222#define VBFS_MOUNT_H
    2323
    24 #define MAX_HOST_NAME 256
    25 #define MAX_NLS_NAME 32
     24#define MAX_HOST_NAME  256
     25#define MAX_NLS_NAME    32
    2626
    2727/* Linux constraints the size of data mount argument to PAGE_SIZE - 1 */
    28 struct vbsf_mount_info {
     28struct vbsf_mount_info_old
     29{
    2930    char name[MAX_HOST_NAME];
    3031    char nls_name[MAX_NLS_NAME];
    31     int uid;
    32     int gid;
    33     int ttl;
     32    int  uid;
     33    int  gid;
     34    int  ttl;
     35};
     36
     37#define VBSF_MOUNT_SIGNATURE_BYTE_0 '\377'
     38#define VBSF_MOUNT_SIGNATURE_BYTE_1 '\376'
     39#define VBSF_MOUNT_SIGNATURE_BYTE_2 '\375'
     40
     41struct vbsf_mount_info_new
     42{
     43    char nullchar;              /* name cannot be '\0' -- we use this field
     44                                   to distinguish between the old structure
     45                                   and the new structure */
     46    char signature[3];          /* signature */
     47    int  length;                /* length of the whole structure */
     48    char name[MAX_HOST_NAME];   /* share name */
     49    char nls_name[MAX_NLS_NAME];/* name of an I/O charset */
     50    int  uid;                   /* user ID for all entries, default 0=root */
     51    int  gid;                   /* group ID for all entries, default 0=root */
     52    int  ttl;                   /* time to live */
     53    int  dmode;                 /* mode for directories if != 0xffffffff */
     54    int  fmode;                 /* mode for regular files if != 0xffffffff */
     55    int  dmask;                 /* umask applied to directories */
     56    int  fmask;                 /* umask applied to regular files */
    3457};
    3558
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c

    r8155 r11507  
    6969/* allocate global info, try to map host share */
    7070static int
    71 sf_glob_alloc (struct vbsf_mount_info *info, struct sf_glob_info **sf_gp)
     71sf_glob_alloc (struct vbsf_mount_info_new *info, struct sf_glob_info **sf_gp)
    7272{
    7373        int err, rc;
     
    8282                LogRelFunc(("could not allocate memory for global info\n"));
    8383                goto fail0;
     84        }
     85
     86        memset(sf_g, sizeof(*sf_g), 0);
     87
     88        if (   info->nullchar     != '\0'
     89            || info->signature[0] != VBSF_MOUNT_SIGNATURE_BYTE_0
     90            || info->signature[1] != VBSF_MOUNT_SIGNATURE_BYTE_1
     91            || info->signature[2] != VBSF_MOUNT_SIGNATURE_BYTE_2)
     92        {
     93            /* An old version of mount.vboxsf made the syscall. Translate the
     94             * old parameters to the new structure. */
     95            struct vbsf_mount_info_old *info_old = (struct vbsf_mount_info_old *)info;
     96            static struct vbsf_mount_info_new info_compat;
     97
     98            info = &info_compat;
     99            memset(info, sizeof(*info), 0);
     100            memcpy(&info->name, &info_old->name, MAX_HOST_NAME);
     101            memcpy(&info->nls_name, &info_old->nls_name, MAX_NLS_NAME);
     102            info->length = offsetof(struct vbsf_mount_info_new, dmode);
     103            info->uid    = info_old->uid;
     104            info->gid    = info_old->gid;
     105            info->ttl    = info_old->ttl;
    84106        }
    85107
     
    127149        }
    128150
    129         sf_g->ttl = info->ttl;
    130         sf_g->uid = info->uid;
    131         sf_g->gid = info->gid;
     151        sf_g->ttl   = info->ttl;
     152        sf_g->uid   = info->uid;
     153        sf_g->gid   = info->gid;
     154
     155        if (info->length >= sizeof(struct vbsf_mount_info_new))
     156        {
     157            /* new fields */
     158            sf_g->dmode = info->dmode;
     159            sf_g->fmode = info->fmode;
     160            sf_g->dmask = info->dmask;
     161            sf_g->fmask = info->fmask;
     162        }
     163        else
     164        {
     165            sf_g->dmode = ~0;
     166            sf_g->fmode = ~0;
     167        }
    132168
    133169        *sf_gp = sf_g;
     
    180216        struct sf_glob_info *sf_g;
    181217        RTFSOBJINFO fsinfo;
    182         struct vbsf_mount_info *info;
     218        struct vbsf_mount_info_new *info;
    183219
    184220        TRACE ();
     
    415451        TRACE ();
    416452
    417         if (sizeof (struct vbsf_mount_info) > PAGE_SIZE) {
     453        if (sizeof (struct vbsf_mount_info_old) > PAGE_SIZE) {
    418454                printk (KERN_ERR
    419455                        "Mount information structure is too large %lu\n"
    420456                        "Must be less than or equal to %lu\n",
    421                         (unsigned long)sizeof (struct vbsf_mount_info),
     457                        (unsigned long)sizeof (struct vbsf_mount_info_old),
    422458                        PAGE_SIZE);
    423459                return -EINVAL;
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.h

    r8155 r11507  
    3636        int uid;
    3737        int gid;
     38        int dmode;
     39        int fmode;
     40        int dmask;
     41        int fmask;
    3842};
    3943
Note: See TracChangeset for help on using the changeset viewer.

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