/usr/src/open-vm-tools-10.0.7/vmblock/linux/file.c is in open-vm-tools-dkms 2:10.0.7-3227872-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | /*********************************************************
* Copyright (C) 2006 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*********************************************************/
/*
* file.c --
*
* File operations for the file system of the vmblock driver.
*
*/
#include "driver-config.h"
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/pagemap.h>
#include "vmblockInt.h"
#include "filesystem.h"
#if defined(VMW_FILLDIR_2618)
typedef u64 inode_num_t;
#else
typedef ino_t inode_num_t;
#endif
/* Specifically for our filldir_t callback */
typedef struct FilldirInfo {
filldir_t filldir;
void *dirent;
} FilldirInfo;
/*
*----------------------------------------------------------------------------
*
* Filldir --
*
* Callback function for readdir that we use in place of the one provided.
* This allows us to specify that each dentry is a symlink, but pass through
* everything else to the original filldir function.
*
* Results:
* Original filldir's return value.
*
* Side effects:
* Directory information gets copied to user's buffer.
*
*----------------------------------------------------------------------------
*/
static int
Filldir(void *buf, // IN: Dirent buffer passed from FileOpReaddir
const char *name, // IN: Dirent name
int namelen, // IN: len of dirent's name
loff_t offset, // IN: Offset
inode_num_t ino, // IN: Inode number of dirent
unsigned int d_type) // IN: Type of file
{
FilldirInfo *info = buf;
/* Specify DT_LNK regardless */
return info->filldir(info->dirent, name, namelen, offset, ino, DT_LNK);
}
/* File operations */
/*
*----------------------------------------------------------------------------
*
* FileOpOpen --
*
* Invoked when open(2) has been called on our root inode. We get an open
* file instance of the actual file that we are providing indirect access
* to.
*
* Results:
* 0 on success, negative error code on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
static int
FileOpOpen(struct inode *inode, // IN
struct file *file) // IN
{
VMBlockInodeInfo *iinfo;
struct file *actualFile;
if (!inode || !file || !INODE_TO_IINFO(inode)) {
Warning("FileOpOpen: invalid args from kernel\n");
return -EINVAL;
}
iinfo = INODE_TO_IINFO(inode);
/*
* Get an open file for the directory we are redirecting to. This ensure we
* can gracefully handle cases where that directory is removed after we are
* mounted.
*/
actualFile = filp_open(iinfo->name, file->f_flags, file->f_flags);
if (IS_ERR(actualFile)) {
Warning("FileOpOpen: could not open file [%s]\n", iinfo->name);
file->private_data = NULL;
return PTR_ERR(actualFile);
}
/*
* If the file opened is the same as the one retrieved for the file then we
* shouldn't allow the open to happen. This can only occur if the
* redirected root directory specified at mount time is the same as where
* the mount is placed. Later in FileOpReaddir() we'd call vfs_readdir()
* and that would try to acquire the inode's semaphore; if the two inodes
* are the same we'll deadlock.
*/
if (actualFile->f_dentry && inode == actualFile->f_dentry->d_inode) {
Warning("FileOpOpen: identical inode encountered, open cannot succeed.\n");
if (filp_close(actualFile, current->files) < 0) {
Warning("FileOpOpen: unable to close opened file.\n");
}
return -EINVAL;
}
file->private_data = actualFile;
return 0;
}
/*
*----------------------------------------------------------------------------
*
* FileOpReaddir --
*
* Invoked when a user invokes getdents(2) or readdir(2) on the root of our
* file system. We perform a readdir on the actual underlying file but
* interpose the callback by providing our own Filldir() function. This
* enables us to change dentry types to symlinks.
*
* Results:
* 0 on success, negative error code on error.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
static int
FileOpReaddir(struct file *file, // IN
void *dirent, // IN
filldir_t filldir) // IN
{
int ret;
FilldirInfo info;
struct file *actualFile;
if (!file) {
Warning("FileOpReaddir: invalid args from kernel\n");
return -EINVAL;
}
actualFile = file->private_data;
if (!actualFile) {
Warning("FileOpReaddir: no actual file found\n");
return -EINVAL;
}
info.filldir = filldir;
info.dirent = dirent;
actualFile->f_pos = file->f_pos;
ret = vfs_readdir(actualFile, Filldir, &info);
file->f_pos = actualFile->f_pos;
return ret;
}
/*
*----------------------------------------------------------------------------
*
* FileOpRelease --
*
* Invoked when a user close(2)s the root of our file system. Here we just
* close the actual file we opened in FileOpOpen().
*
* Results:
* 0 on success, negative value on error.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
static int
FileOpRelease(struct inode *inode, // IN
struct file *file) // IN
{
int ret;
struct file *actualFile;
if (!inode || !file) {
Warning("FileOpRelease: invalid args from kerel\n");
return -EINVAL;
}
actualFile = file->private_data;
if (!actualFile) {
Warning("FileOpRelease: no actual file found\n");
return -EINVAL;
}
ret = filp_close(actualFile, current->files);
return ret;
}
struct file_operations RootFileOps = {
.readdir = FileOpReaddir,
.open = FileOpOpen,
.release = FileOpRelease,
};
|