Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: MIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * VirtualBox Guest Shared Folders support: Directory inode and file operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006-2018 Oracle Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/vbox_utils.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "vfsmod.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static int vboxsf_dir_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	struct shfl_createparms params = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct vboxsf_dir_info *sf_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	sf_d = vboxsf_dir_info_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (!sf_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	params.handle = SHFL_HANDLE_NIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	params.create_flags = SHFL_CF_DIRECTORY | SHFL_CF_ACT_OPEN_IF_EXISTS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 			      SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	err = vboxsf_create_at_dentry(file_dentry(file), &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		goto err_free_dir_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (params.result != SHFL_FILE_EXISTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		goto err_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	err = vboxsf_dir_read_all(sbi, sf_d, params.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		goto err_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	vboxsf_close(sbi->root, params.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	file->private_data = sf_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) err_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	vboxsf_close(sbi->root, params.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) err_free_dir_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	vboxsf_dir_info_free(sf_d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int vboxsf_dir_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (file->private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		vboxsf_dir_info_free(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static unsigned int vboxsf_get_d_type(u32 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	unsigned int d_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	switch (mode & SHFL_TYPE_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case SHFL_TYPE_FIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		d_type = DT_FIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	case SHFL_TYPE_DEV_CHAR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		d_type = DT_CHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	case SHFL_TYPE_DIRECTORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		d_type = DT_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case SHFL_TYPE_DEV_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		d_type = DT_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	case SHFL_TYPE_FILE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		d_type = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	case SHFL_TYPE_SYMLINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		d_type = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	case SHFL_TYPE_SOCKET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		d_type = DT_SOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	case SHFL_TYPE_WHITEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		d_type = DT_WHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		d_type = DT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return d_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static bool vboxsf_dir_emit(struct file *dir, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(file_inode(dir)->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct vboxsf_dir_info *sf_d = dir->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct shfl_dirinfo *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct vboxsf_dir_buf *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	unsigned int d_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	loff_t i, cur = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ino_t fake_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	void *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	list_for_each_entry(b, &sf_d->info_list, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) try_next_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (ctx->pos >= cur + b->entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			cur += b->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		 * Note the vboxsf_dir_info objects we are iterating over here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		 * are variable sized, so the info pointer may end up being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 * unaligned. This is how we get the data from the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		 * Since vboxsf is only supported on x86 machines this is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 * a problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		for (i = 0, info = b->buf; i < ctx->pos - cur; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			end = &info->name.string.utf8[info->name.size];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			/* Only happens if the host gives us corrupt data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			if (WARN_ON(end > (b->buf + b->used)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			info = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		end = &info->name.string.utf8[info->name.size];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (WARN_ON(end > (b->buf + b->used)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		/* Info now points to the right entry, emit it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		d_type = vboxsf_get_d_type(info->info.attr.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		 * On 32-bit systems pos is 64-bit signed, while ino is 32-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		 * unsigned so fake_ino may overflow, check for this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if ((ino_t)(ctx->pos + 1) != (u64)(ctx->pos + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			vbg_err("vboxsf: fake ino overflow, truncating dir\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		fake_ino = ctx->pos + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (sbi->nls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			char d_name[NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			err = vboxsf_nlscpy(sbi, d_name, NAME_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					    info->name.string.utf8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					    info->name.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				/* skip erroneous entry and proceed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				ctx->pos += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				goto try_next_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			return dir_emit(ctx, d_name, strlen(d_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					fake_ino, d_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return dir_emit(ctx, info->name.string.utf8, info->name.length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				fake_ino, d_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int vboxsf_dir_iterate(struct file *dir, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bool emitted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		emitted = vboxsf_dir_emit(dir, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (emitted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			ctx->pos += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	} while (emitted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) const struct file_operations vboxsf_dir_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.open = vboxsf_dir_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.iterate = vboxsf_dir_iterate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.release = vboxsf_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.read = generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * This is called during name resolution/lookup to check if the @dentry in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * the cache is still valid. the job is handled by vboxsf_inode_revalidate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static int vboxsf_dentry_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (flags & LOOKUP_RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return vboxsf_inode_revalidate(dentry) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return vboxsf_stat_dentry(dentry, NULL) == -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) const struct dentry_operations vboxsf_dentry_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.d_revalidate = vboxsf_dentry_revalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* iops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static struct dentry *vboxsf_dir_lookup(struct inode *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 					struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct shfl_fsobjinfo fsinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	dentry->d_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	err = vboxsf_stat_dentry(dentry, &fsinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		inode = (err == -ENOENT) ? NULL : ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		inode = vboxsf_new_inode(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (!IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			vboxsf_init_inode(sbi, inode, &fsinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int vboxsf_dir_instantiate(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				  struct shfl_fsobjinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct vboxsf_inode *sf_i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	inode = vboxsf_new_inode(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	sf_i = VBOXSF_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* The host may have given us different attr then requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	sf_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	vboxsf_init_inode(sbi, inode, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int vboxsf_dir_create(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			     umode_t mode, bool is_dir, bool excl, u64 *handle_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct vboxsf_inode *sf_parent_i = VBOXSF_I(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct shfl_createparms params = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	params.handle = SHFL_HANDLE_NIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	params.create_flags = SHFL_CF_ACT_CREATE_IF_NEW | SHFL_CF_ACCESS_READWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (is_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		params.create_flags |= SHFL_CF_DIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		params.create_flags |= SHFL_CF_ACT_FAIL_IF_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	params.info.attr.mode = (mode & 0777) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				(is_dir ? SHFL_TYPE_DIRECTORY : SHFL_TYPE_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	params.info.attr.additional = SHFLFSOBJATTRADD_NOTHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	err = vboxsf_create_at_dentry(dentry, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (params.result != SHFL_FILE_CREATED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	err = vboxsf_dir_instantiate(parent, dentry, &params.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	/* parent directory access/change time changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	sf_parent_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (err == 0 && handle_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		*handle_ret = params.handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		vboxsf_close(sbi->root, params.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int vboxsf_dir_mkfile(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			     umode_t mode, bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return vboxsf_dir_create(parent, dentry, mode, false, excl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int vboxsf_dir_mkdir(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			    umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return vboxsf_dir_create(parent, dentry, mode, true, true, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				  struct file *file, unsigned int flags, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct vboxsf_handle *sf_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct dentry *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	u64 handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (d_in_lookup(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		res = vboxsf_dir_lookup(parent, dentry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		if (IS_ERR(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			return PTR_ERR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			dentry = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	/* Only creates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (!(flags & O_CREAT) || d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return finish_no_open(file, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	err = vboxsf_dir_create(parent, dentry, mode, false, flags & O_EXCL, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	sf_handle = vboxsf_create_sf_handle(d_inode(dentry), handle, SHFL_CF_ACCESS_READWRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (IS_ERR(sf_handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		vboxsf_close(sbi->root, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		err = PTR_ERR(sf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	err = finish_open(file, dentry, generic_file_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		/* This also closes the handle passed to vboxsf_create_sf_handle() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		vboxsf_release_sf_handle(d_inode(dentry), sf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	file->private_data = sf_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	file->f_mode |= FMODE_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	dput(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int vboxsf_dir_unlink(struct inode *parent, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct vboxsf_inode *sf_parent_i = VBOXSF_I(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct shfl_string *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		flags = SHFL_REMOVE_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		flags = SHFL_REMOVE_FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		flags |= SHFL_REMOVE_SYMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	path = vboxsf_path_from_dentry(sbi, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (IS_ERR(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return PTR_ERR(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	err = vboxsf_remove(sbi->root, path, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	__putname(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	/* parent directory access/change time changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	sf_parent_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static int vboxsf_dir_rename(struct inode *old_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			     struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			     struct inode *new_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			     struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			     unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(old_parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct vboxsf_inode *sf_old_parent_i = VBOXSF_I(old_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct vboxsf_inode *sf_new_parent_i = VBOXSF_I(new_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	u32 shfl_flags = SHFL_RENAME_FILE | SHFL_RENAME_REPLACE_IF_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct shfl_string *old_path, *new_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	old_path = vboxsf_path_from_dentry(sbi, old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (IS_ERR(old_path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return PTR_ERR(old_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	new_path = vboxsf_path_from_dentry(sbi, new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (IS_ERR(new_path)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		err = PTR_ERR(new_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		goto err_put_old_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (d_inode(old_dentry)->i_mode & S_IFDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		shfl_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	err = vboxsf_rename(sbi->root, old_path, new_path, shfl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		/* parent directories access/change time changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		sf_new_parent_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		sf_old_parent_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	__putname(new_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) err_put_old_path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	__putname(old_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int vboxsf_dir_symlink(struct inode *parent, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			      const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct vboxsf_inode *sf_parent_i = VBOXSF_I(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	int symname_size = strlen(symname) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct shfl_string *path, *ssymname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct shfl_fsobjinfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	path = vboxsf_path_from_dentry(sbi, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (IS_ERR(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		return PTR_ERR(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	ssymname = kmalloc(SHFLSTRING_HEADER_SIZE + symname_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (!ssymname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		__putname(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ssymname->length = symname_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	ssymname->size = symname_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	memcpy(ssymname->string.utf8, symname, symname_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	err = vboxsf_symlink(sbi->root, path, ssymname, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	kfree(ssymname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	__putname(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		/* -EROFS means symlinks are note support -> -EPERM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		return (err == -EROFS) ? -EPERM : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	err = vboxsf_dir_instantiate(parent, dentry, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	/* parent directory access/change time changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	sf_parent_i->force_restat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) const struct inode_operations vboxsf_dir_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	.lookup  = vboxsf_dir_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	.create  = vboxsf_dir_mkfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	.mkdir   = vboxsf_dir_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	.atomic_open = vboxsf_dir_atomic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	.rmdir   = vboxsf_dir_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	.unlink  = vboxsf_dir_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	.rename  = vboxsf_dir_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	.symlink = vboxsf_dir_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	.getattr = vboxsf_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	.setattr = vboxsf_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) };