diff mbox

[PATCHv1,1/2] libfs: allow simple_fill_super() to add symlinks

Message ID 1463420646-29530-2-git-send-email-david.vrabel@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Vrabel May 16, 2016, 5:44 p.m. UTC
simple_fill_super() will add symlinks if an entry has mode & S_IFLNK.
The target is provided in the new "link" field.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 fs/libfs.c         | 23 ++++++++++++++++++++---
 include/linux/fs.h |  2 +-
 2 files changed, 21 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/fs/libfs.c b/fs/libfs.c
index f3fa82c..894e182 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -500,6 +500,8 @@  int simple_fill_super(struct super_block *s, unsigned long magic,
 	if (!root)
 		return -ENOMEM;
 	for (i = 0; !files->name || files->name[0]; i++, files++) {
+		char *link = NULL;
+
 		if (!files->name)
 			continue;
 
@@ -509,17 +511,32 @@  int simple_fill_super(struct super_block *s, unsigned long magic,
 				"with an index of 1!\n", __func__,
 				s->s_type->name);
 
+		if (files->mode & S_IFLNK) {
+			link = kstrdup(files->link, GFP_KERNEL);
+			if (!link)
+				goto out;
+		}
+
 		dentry = d_alloc_name(root, files->name);
-		if (!dentry)
+		if (!dentry) {
+			kfree(link);
 			goto out;
+		}
 		inode = new_inode(s);
 		if (!inode) {
 			dput(dentry);
+			kfree(link);
 			goto out;
 		}
-		inode->i_mode = S_IFREG | files->mode;
+		inode->i_mode = files->mode;
+		if (files->mode & S_IFLNK) {
+			inode->i_op = &simple_symlink_inode_operations;
+			inode->i_link = link;
+		} else {
+			inode->i_fop = files->ops;
+			inode->i_mode |= S_IFREG;
+		}
 		inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
-		inode->i_fop = files->ops;
 		inode->i_ino = i;
 		d_add(dentry, inode);
 	}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 70e61b5..8a09998 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2897,7 +2897,7 @@  extern const struct file_operations simple_dir_operations;
 extern const struct inode_operations simple_dir_inode_operations;
 extern void make_empty_dir_inode(struct inode *inode);
 extern bool is_empty_dir_inode(struct inode *inode);
-struct tree_descr { char *name; const struct file_operations *ops; int mode; };
+struct tree_descr { char *name; const struct file_operations *ops; int mode; char *link; };
 struct dentry *d_alloc_name(struct dentry *, const char *);
 extern int simple_fill_super(struct super_block *, unsigned long, struct tree_descr *);
 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);