VirtualBox

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

最後變更 在這個檔案從31203是 31203,由 vboxsync 提交於 15 年 前

Tabs, spaces.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 2.3 KB
 
1/* $Id: vbsfmount.c 31203 2010-07-29 12:44:41Z 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 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.alldomusa.eu.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#include <ctype.h>
22#include <mntent.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/mount.h>
27
28
29/** @todo Use defines for return values! */
30int vbsfmount_complete(const char *host_name, const char *mount_point,
31 unsigned long flags, struct vbsf_mount_opts *opts)
32{
33 FILE *f, *m;
34 char *buf;
35 size_t size;
36 struct mntent e;
37 int rc = 0;
38
39 m = open_memstream(&buf, &size);
40 if (!m)
41 return 1; /* Could not update mount table (failed to create memstream). */
42
43 if (opts->uid)
44 fprintf(m, "uid=%d,", opts->uid);
45 if (opts->gid)
46 fprintf(m, "gid=%d,", opts->gid);
47 if (opts->ttl)
48 fprintf(m, "ttl=%d,", opts->ttl);
49 if (*opts->nls_name)
50 fprintf(m, "iocharset=%s,", opts->nls_name);
51 if (flags & MS_NOSUID)
52 fprintf(m, "%s,", MNTOPT_NOSUID);
53 if (flags & MS_RDONLY)
54 fprintf(m, "%s,", MNTOPT_RO);
55 else
56 fprintf(m, "%s,", MNTOPT_RW);
57
58 fclose(m);
59
60 if (size > 0)
61 buf[size - 1] = 0;
62 else
63 buf = "defaults";
64
65 f = setmntent(MOUNTED, "a+");
66 if (!f)
67 {
68 rc = 2; /* Could not open mount table for update. */
69 }
70 else
71 {
72 e.mnt_fsname = (char*)host_name;
73 e.mnt_dir = (char*)mount_point;
74 e.mnt_type = "vboxsf";
75 e.mnt_opts = buf;
76 e.mnt_freq = 0;
77 e.mnt_passno = 0;
78
79 if (addmntent(f, &e))
80 rc = 3; /* Could not add an entry to the mount table. */
81
82 endmntent(f);
83 }
84
85 if (size > 0)
86 {
87 memset(buf, 0, size);
88 free(buf);
89 }
90
91 return rc;
92}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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