VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.c@ 77138

Last change on this file since 77138 was 77138, checked in by vboxsync, 6 years ago

linux/vboxsf: More read code tweaking, making the max read/write buffer size configurable (mount option maxiopages). Also added code for dealing with the host running out of heap. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/* $Id: vbsfmount.c 77138 2019-02-01 19:00:23Z vboxsync $ */
2/** @file
3 * vbsfmount - Commonly used code to mount shared folders on Linux-based
4 * systems. Currently used by mount.vboxsf and VBoxService.
5 */
6
7/*
8 * Copyright (C) 2010-2019 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "vbsfmount.h"
20
21#ifndef _GNU_SOURCE
22#define _GNU_SOURCE
23#endif
24#include <ctype.h>
25#include <mntent.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <sys/mount.h>
30
31
32/** @todo Use defines for return values! */
33int vbsfmount_complete(const char *host_name, const char *mount_point,
34 unsigned long flags, struct vbsf_mount_opts *opts)
35{
36 FILE *f, *m;
37 char *buf;
38 size_t size;
39 struct mntent e;
40 int rc = 0;
41
42 m = open_memstream(&buf, &size);
43 if (!m)
44 return 1; /* Could not update mount table (failed to create memstream). */
45
46 if (opts->uid)
47 fprintf(m, "uid=%d,", opts->uid);
48 if (opts->gid)
49 fprintf(m, "gid=%d,", opts->gid);
50 if (opts->ttl)
51 fprintf(m, "ttl=%d,", opts->ttl);
52 if (*opts->nls_name)
53 fprintf(m, "iocharset=%s,", opts->nls_name);
54 if (flags & MS_NOSUID)
55 fprintf(m, "%s,", MNTOPT_NOSUID);
56 if (flags & MS_RDONLY)
57 fprintf(m, "%s,", MNTOPT_RO);
58 else
59 fprintf(m, "%s,", MNTOPT_RW);
60 if (opts->cMaxIoPages)
61 fprintf(m, "maxiopages=%u,", opts->cMaxIoPages);
62
63 fclose(m);
64
65 if (size > 0)
66 buf[size - 1] = 0;
67 else
68 buf = "defaults";
69
70 f = setmntent(MOUNTED, "a+");
71 if (!f)
72 {
73 rc = 2; /* Could not open mount table for update. */
74 }
75 else
76 {
77 e.mnt_fsname = (char*)host_name;
78 e.mnt_dir = (char*)mount_point;
79 e.mnt_type = "vboxsf";
80 e.mnt_opts = buf;
81 e.mnt_freq = 0;
82 e.mnt_passno = 0;
83
84 if (addmntent(f, &e))
85 rc = 3; /* Could not add an entry to the mount table. */
86
87 endmntent(f);
88 }
89
90 if (size > 0)
91 {
92 memset(buf, 0, size);
93 free(buf);
94 }
95
96 return rc;
97}
Note: See TracBrowser for help on using the repository browser.

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