Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git linux/control.c linux/control.c
index 79716bd..2815f4f 100644
--- linux/control.c
+++ linux/control.c
@@ -208,9 +208,11 @@ SetupProcDevice(void)
VMBlockSetProcEntryOwner(controlProcMountpoint);
/* Create /proc/fs/vmblock/dev */
- controlProcEntry = create_proc_entry(VMBLOCK_CONTROL_DEVNAME,
- VMBLOCK_CONTROL_MODE,
- controlProcDirEntry);
+ controlProcEntry = proc_create(VMBLOCK_CONTROL_DEVNAME,
+ VMBLOCK_CONTROL_MODE,
+ controlProcDirEntry,
+ &ControlFileOps);
+
if (!controlProcEntry) {
Warning("SetupProcDevice: could not create " VMBLOCK_DEVICE "\n");
remove_proc_entry(VMBLOCK_CONTROL_MOUNTPOINT, controlProcDirEntry);
@@ -218,7 +220,10 @@ SetupProcDevice(void)
return -EINVAL;
}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
controlProcEntry->proc_fops = &ControlFileOps;
+#endif
+
return 0;
}
@@ -282,18 +287,24 @@ ExecuteBlockOp(const char __user *buf, // IN: buffer with name
int i;
int retval;
- name = getname(buf);
+ name = __getname();
if (IS_ERR(name)) {
return PTR_ERR(name);
}
+ i = strncpy_from_user(name, buf, PATH_MAX);
+ if (i < 0 || i == PATH_MAX) {
+ __putname(name);
+ return -EINVAL;
+ }
+
for (i = strlen(name) - 1; i >= 0 && name[i] == '/'; i--) {
name[i] = '\0';
}
retval = i < 0 ? -EINVAL : blockOp(name, blocker);
- putname(name);
+ __putname(name);
return retval;
}
diff --git linux/dentry.c linux/dentry.c
index 05ea95a..e992cfd 100644
--- linux/dentry.c
+++ linux/dentry.c
@@ -63,7 +63,7 @@ DentryOpRevalidate(struct dentry *dentry, // IN: dentry revalidating
struct nameidata *nd) // IN: lookup flags & intent
{
VMBlockInodeInfo *iinfo;
- struct nameidata actualNd;
+ struct path actualNd;
struct dentry *actualDentry;
int ret;
diff --git linux/file.c linux/file.c
index d7ac1f6..36e1d95 100644
--- linux/file.c
+++ linux/file.c
@@ -132,7 +132,7 @@ FileOpOpen(struct inode *inode, // IN
* 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) {
+ if (actualFile->f_path.dentry && inode == actualFile->f_path.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");
@@ -166,11 +166,9 @@ FileOpOpen(struct inode *inode, // IN
static int
FileOpReaddir(struct file *file, // IN
- void *dirent, // IN
- filldir_t filldir) // IN
+ struct dir_context *ctx)
{
int ret;
- FilldirInfo info;
struct file *actualFile;
if (!file) {
@@ -184,11 +182,8 @@ FileOpReaddir(struct file *file, // IN
return -EINVAL;
}
- info.filldir = filldir;
- info.dirent = dirent;
-
actualFile->f_pos = file->f_pos;
- ret = vfs_readdir(actualFile, Filldir, &info);
+ ret = iterate_dir(actualFile, ctx);
file->f_pos = actualFile->f_pos;
return ret;
@@ -237,7 +232,7 @@ FileOpRelease(struct inode *inode, // IN
struct file_operations RootFileOps = {
- .readdir = FileOpReaddir,
+ .iterate = FileOpReaddir,
.open = FileOpOpen,
.release = FileOpRelease,
};
diff --git linux/filesystem.c linux/filesystem.c
index af57499..931fad0 100644
--- linux/filesystem.c
+++ linux/filesystem.c
@@ -322,7 +322,7 @@ Iget(struct super_block *sb, // IN: file system superblock object
{
VMBlockInodeInfo *iinfo;
struct inode *inode;
- struct nameidata actualNd;
+ struct path actualNd;
ASSERT(sb);
diff --git linux/inode.c linux/inode.c
index 098c94c..5da1ff5 100644
--- linux/inode.c
+++ linux/inode.c
@@ -35,10 +35,18 @@
/* Inode operations */
-static struct dentry *InodeOpLookup(struct inode *dir,
- struct dentry *dentry, struct nameidata *nd);
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
+static struct dentry *InodeOpLookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd);
static int InodeOpReadlink(struct dentry *dentry, char __user *buffer, int buflen);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
+#else
+static struct dentry *InodeOpLookup(struct inode *, struct dentry *, unsigned int);
+static int InodeOpReadlink(struct dentry *, char __user *, int);
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+static const char *InodeOpFollowlink(struct dentry *dentry, void **cookie);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
static void *InodeOpFollowlink(struct dentry *dentry, struct nameidata *nd);
#else
static int InodeOpFollowlink(struct dentry *dentry, struct nameidata *nd);
@@ -49,12 +57,15 @@ struct inode_operations RootInodeOps = {
.lookup = InodeOpLookup,
};
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
static struct inode_operations LinkInodeOps = {
+#else
+struct inode_operations LinkInodeOps = {
+#endif
.readlink = InodeOpReadlink,
.follow_link = InodeOpFollowlink,
};
-
/*
*----------------------------------------------------------------------------
*
@@ -75,7 +86,11 @@ static struct inode_operations LinkInodeOps = {
static struct dentry *
InodeOpLookup(struct inode *dir, // IN: parent directory's inode
struct dentry *dentry, // IN: dentry to lookup
- struct nameidata *nd) // IN: lookup intent and information
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
+ struct nameidata *nd) // IN: lookup intent and information
+#else
+ unsigned int flags)
+#endif
{
char *filename;
struct inode *inode;
@@ -135,7 +150,12 @@ InodeOpLookup(struct inode *dir, // IN: parent directory's inode
inode->i_size = INODE_TO_IINFO(inode)->nameLen;
inode->i_version = 1;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
inode->i_uid = inode->i_gid = 0;
+#else
+ inode->i_gid = make_kgid(current_user_ns(), 0);
+ inode->i_uid = make_kuid(current_user_ns(), 0);
+#endif
inode->i_op = &LinkInodeOps;
d_add(dentry, inode);
@@ -177,7 +197,12 @@ InodeOpReadlink(struct dentry *dentry, // IN : dentry of symlink
return -EINVAL;
}
- return vfs_readlink(dentry, buffer, buflen, iinfo->name);
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 99)
+ return vfs_readlink(dentry, buffer, buflen, iinfo->name);
+#else
+ return readlink_copy(buffer, buflen, iinfo->name);
+#endif
+
}
@@ -198,13 +223,20 @@ InodeOpReadlink(struct dentry *dentry, // IN : dentry of symlink
*----------------------------------------------------------------------------
*/
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+static const char *
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
static void *
#else
static int
#endif
InodeOpFollowlink(struct dentry *dentry, // IN : dentry of symlink
- struct nameidata *nd) // OUT: stores result
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+ void **cookie
+#else
+ struct nameidata *nd
+#endif
+ ) // OUT: stores result
{
int ret;
VMBlockInodeInfo *iinfo;
@@ -221,7 +253,11 @@ InodeOpFollowlink(struct dentry *dentry, // IN : dentry of symlink
goto out;
}
- ret = vfs_follow_link(nd, iinfo->name);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+ return *cookie = (char *)(iinfo->name);
+#else
+ nd_set_link(nd, iinfo->name);
+#endif
out:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
@@ -230,3 +266,4 @@ out:
return ret;
#endif
}
+
diff --git shared/compat_namei.h shared/compat_namei.h
index f82dd49..1b2417d 100644
--- shared/compat_namei.h
+++ shared/compat_namei.h
@@ -26,21 +26,21 @@
* struct. They were both replaced with a struct path.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
-#define compat_vmw_nd_to_dentry(nd) (nd).path.dentry
+#define compat_vmw_nd_to_dentry(nd) (nd).dentry
#else
#define compat_vmw_nd_to_dentry(nd) (nd).dentry
#endif
/* In 2.6.25-rc2, path_release(&nd) was replaced with path_put(&nd.path). */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
-#define compat_path_release(nd) path_put(&(nd)->path)
+#define compat_path_release(nd) path_put(nd)
#else
#define compat_path_release(nd) path_release(nd)
#endif
/* path_lookup was removed in 2.6.39 merge window VFS merge */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
-#define compat_path_lookup(name, flags, nd) kern_path(name, flags, &((nd)->path))
+#define compat_path_lookup(name, flags, nd) kern_path(name, flags, nd)
#else
#define compat_path_lookup(name, flags, nd) path_lookup(name, flags, nd)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment