Changeset 70786 in vbox for trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c
- Timestamp:
- Jan 29, 2018 10:57:10 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c
r69500 r70786 52 52 53 53 /* allocate global info, try to map host share */ 54 static int sf_glob_alloc(struct vbsf_mount_info_new *info, struct sf_glob_info **sf_gp) 55 { 56 int err, rc; 57 SHFLSTRING *str_name; 58 size_t name_len, str_len; 59 struct sf_glob_info *sf_g; 60 61 TRACE(); 62 sf_g = kmalloc(sizeof(*sf_g), GFP_KERNEL); 63 if (!sf_g) 64 { 65 err = -ENOMEM; 66 LogRelFunc(("could not allocate memory for global info\n")); 67 goto fail0; 68 } 69 70 RT_ZERO(*sf_g); 71 72 if ( info->nullchar != '\0' 73 || info->signature[0] != VBSF_MOUNT_SIGNATURE_BYTE_0 74 || info->signature[1] != VBSF_MOUNT_SIGNATURE_BYTE_1 75 || info->signature[2] != VBSF_MOUNT_SIGNATURE_BYTE_2) 76 { 77 err = -EINVAL; 78 goto fail1; 79 } 80 81 info->name[sizeof(info->name) - 1] = 0; 82 info->nls_name[sizeof(info->nls_name) - 1] = 0; 83 84 name_len = strlen(info->name); 85 str_len = offsetof(SHFLSTRING, String.utf8) + name_len + 1; 86 str_name = kmalloc(str_len, GFP_KERNEL); 87 if (!str_name) 88 { 89 err = -ENOMEM; 90 LogRelFunc(("could not allocate memory for host name\n")); 91 goto fail1; 92 } 93 94 str_name->u16Length = name_len; 95 str_name->u16Size = name_len + 1; 96 memcpy(str_name->String.utf8, info->name, name_len + 1); 54 static int sf_glob_alloc(struct vbsf_mount_info_new *info, 55 struct sf_glob_info **sf_gp) 56 { 57 int err, rc; 58 SHFLSTRING *str_name; 59 size_t name_len, str_len; 60 struct sf_glob_info *sf_g; 61 62 TRACE(); 63 sf_g = kmalloc(sizeof(*sf_g), GFP_KERNEL); 64 if (!sf_g) { 65 err = -ENOMEM; 66 LogRelFunc(("could not allocate memory for global info\n")); 67 goto fail0; 68 } 69 70 RT_ZERO(*sf_g); 71 72 if (info->nullchar != '\0' 73 || info->signature[0] != VBSF_MOUNT_SIGNATURE_BYTE_0 74 || info->signature[1] != VBSF_MOUNT_SIGNATURE_BYTE_1 75 || info->signature[2] != VBSF_MOUNT_SIGNATURE_BYTE_2) { 76 err = -EINVAL; 77 goto fail1; 78 } 79 80 info->name[sizeof(info->name) - 1] = 0; 81 info->nls_name[sizeof(info->nls_name) - 1] = 0; 82 83 name_len = strlen(info->name); 84 str_len = offsetof(SHFLSTRING, String.utf8) + name_len + 1; 85 str_name = kmalloc(str_len, GFP_KERNEL); 86 if (!str_name) { 87 err = -ENOMEM; 88 LogRelFunc(("could not allocate memory for host name\n")); 89 goto fail1; 90 } 91 92 str_name->u16Length = name_len; 93 str_name->u16Size = name_len + 1; 94 memcpy(str_name->String.utf8, info->name, name_len + 1); 97 95 98 96 #define _IS_UTF8(_str) \ … … 101 99 (strcmp(_str, "") == 0) 102 100 103 /* Check if NLS charset is valid and not points to UTF8 table */ 104 if (info->nls_name[0]) 105 { 106 if (_IS_UTF8(info->nls_name)) 107 sf_g->nls = NULL; 108 else 109 { 110 sf_g->nls = load_nls(info->nls_name); 111 if (!sf_g->nls) 112 { 113 err = -EINVAL; 114 LogFunc(("failed to load nls %s\n", info->nls_name)); 115 kfree(str_name); 116 goto fail1; 117 } 118 } 119 } 120 else 121 { 101 /* Check if NLS charset is valid and not points to UTF8 table */ 102 if (info->nls_name[0]) { 103 if (_IS_UTF8(info->nls_name)) 104 sf_g->nls = NULL; 105 else { 106 sf_g->nls = load_nls(info->nls_name); 107 if (!sf_g->nls) { 108 err = -EINVAL; 109 LogFunc(("failed to load nls %s\n", 110 info->nls_name)); 111 kfree(str_name); 112 goto fail1; 113 } 114 } 115 } else { 122 116 #ifdef CONFIG_NLS_DEFAULT 123 /* If no NLS charset specified, try to load the default 124 * one if it's not points to UTF8. */ 125 if (!_IS_UTF8(CONFIG_NLS_DEFAULT) && !_IS_EMPTY(CONFIG_NLS_DEFAULT)) 126 sf_g->nls = load_nls_default(); 127 else 128 sf_g->nls = NULL; 129 #else 130 sf_g->nls = NULL; 117 /* If no NLS charset specified, try to load the default 118 * one if it's not points to UTF8. */ 119 if (!_IS_UTF8(CONFIG_NLS_DEFAULT) 120 && !_IS_EMPTY(CONFIG_NLS_DEFAULT)) 121 sf_g->nls = load_nls_default(); 122 else 123 sf_g->nls = NULL; 124 #else 125 sf_g->nls = NULL; 131 126 #endif 132 127 133 128 #undef _IS_UTF8 134 129 #undef _IS_EMPTY 135 } 136 137 rc = VbglR0SfMapFolder(&client_handle, str_name, &sf_g->map); 138 kfree(str_name); 139 140 if (RT_FAILURE(rc)) 141 { 142 err = -EPROTO; 143 LogFunc(("VbglR0SfMapFolder failed rc=%d\n", rc)); 144 goto fail2; 145 } 146 147 sf_g->ttl = info->ttl; 148 sf_g->uid = info->uid; 149 sf_g->gid = info->gid; 150 151 if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) 152 { 153 /* new fields */ 154 sf_g->dmode = info->dmode; 155 sf_g->fmode = info->fmode; 156 sf_g->dmask = info->dmask; 157 sf_g->fmask = info->fmask; 158 } 159 else 160 { 161 sf_g->dmode = ~0; 162 sf_g->fmode = ~0; 163 } 164 165 *sf_gp = sf_g; 166 return 0; 167 168 fail2: 169 if (sf_g->nls) 170 unload_nls(sf_g->nls); 171 172 fail1: 173 kfree(sf_g); 174 175 fail0: 176 return err; 130 } 131 132 rc = VbglR0SfMapFolder(&client_handle, str_name, &sf_g->map); 133 kfree(str_name); 134 135 if (RT_FAILURE(rc)) { 136 err = -EPROTO; 137 LogFunc(("VbglR0SfMapFolder failed rc=%d\n", rc)); 138 goto fail2; 139 } 140 141 sf_g->ttl = info->ttl; 142 sf_g->uid = info->uid; 143 sf_g->gid = info->gid; 144 145 if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) { 146 /* new fields */ 147 sf_g->dmode = info->dmode; 148 sf_g->fmode = info->fmode; 149 sf_g->dmask = info->dmask; 150 sf_g->fmask = info->fmask; 151 } else { 152 sf_g->dmode = ~0; 153 sf_g->fmode = ~0; 154 } 155 156 *sf_gp = sf_g; 157 return 0; 158 159 fail2: 160 if (sf_g->nls) 161 unload_nls(sf_g->nls); 162 163 fail1: 164 kfree(sf_g); 165 166 fail0: 167 return err; 177 168 } 178 169 179 170 /* unmap the share and free global info [sf_g] */ 180 static void 181 sf_glob_free(struct sf_glob_info *sf_g) 182 { 183 int rc; 184 185 TRACE(); 186 rc = VbglR0SfUnmapFolder(&client_handle, &sf_g->map); 187 if (RT_FAILURE(rc)) 188 LogFunc(("VbglR0SfUnmapFolder failed rc=%d\n", rc)); 189 190 if (sf_g->nls) 191 unload_nls(sf_g->nls); 192 193 kfree(sf_g); 171 static void sf_glob_free(struct sf_glob_info *sf_g) 172 { 173 int rc; 174 175 TRACE(); 176 rc = VbglR0SfUnmapFolder(&client_handle, &sf_g->map); 177 if (RT_FAILURE(rc)) 178 LogFunc(("VbglR0SfUnmapFolder failed rc=%d\n", rc)); 179 180 if (sf_g->nls) 181 unload_nls(sf_g->nls); 182 183 kfree(sf_g); 194 184 } 195 185 … … 207 197 static int sf_read_super_aux(struct super_block *sb, void *data, int flags) 208 198 { 209 int err; 210 struct dentry *droot; 211 struct inode *iroot; 212 struct sf_inode_info *sf_i; 213 struct sf_glob_info *sf_g; 214 SHFLFSOBJINFO fsinfo; 215 struct vbsf_mount_info_new *info; 216 bool fInodePut = true; 217 218 TRACE(); 219 if (!data) 220 { 221 LogFunc(("no mount info specified\n")); 222 return -EINVAL; 223 } 224 225 info = data; 226 227 if (flags & MS_REMOUNT) 228 { 229 LogFunc(("remounting is not supported\n")); 230 return -ENOSYS; 231 } 232 233 err = sf_glob_alloc(info, &sf_g); 234 if (err) 235 goto fail0; 236 237 sf_i = kmalloc(sizeof (*sf_i), GFP_KERNEL); 238 if (!sf_i) 239 { 240 err = -ENOMEM; 241 LogRelFunc(("could not allocate memory for root inode info\n")); 242 goto fail1; 243 } 244 245 sf_i->handle = SHFL_HANDLE_NIL; 246 sf_i->path = kmalloc(sizeof(SHFLSTRING) + 1, GFP_KERNEL); 247 if (!sf_i->path) 248 { 249 err = -ENOMEM; 250 LogRelFunc(("could not allocate memory for root inode path\n")); 251 goto fail2; 252 } 253 254 sf_i->path->u16Length = 1; 255 sf_i->path->u16Size = 2; 256 sf_i->path->String.utf8[0] = '/'; 257 sf_i->path->String.utf8[1] = 0; 258 sf_i->force_reread = 0; 259 260 err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0); 261 if (err) 262 { 263 LogFunc(("could not stat root of share\n")); 264 goto fail3; 265 } 266 267 sb->s_magic = 0xface; 268 sb->s_blocksize = 1024; 199 int err; 200 struct dentry *droot; 201 struct inode *iroot; 202 struct sf_inode_info *sf_i; 203 struct sf_glob_info *sf_g; 204 SHFLFSOBJINFO fsinfo; 205 struct vbsf_mount_info_new *info; 206 bool fInodePut = true; 207 208 TRACE(); 209 if (!data) { 210 LogFunc(("no mount info specified\n")); 211 return -EINVAL; 212 } 213 214 info = data; 215 216 if (flags & MS_REMOUNT) { 217 LogFunc(("remounting is not supported\n")); 218 return -ENOSYS; 219 } 220 221 err = sf_glob_alloc(info, &sf_g); 222 if (err) 223 goto fail0; 224 225 sf_i = kmalloc(sizeof(*sf_i), GFP_KERNEL); 226 if (!sf_i) { 227 err = -ENOMEM; 228 LogRelFunc(("could not allocate memory for root inode info\n")); 229 goto fail1; 230 } 231 232 sf_i->handle = SHFL_HANDLE_NIL; 233 sf_i->path = kmalloc(sizeof(SHFLSTRING) + 1, GFP_KERNEL); 234 if (!sf_i->path) { 235 err = -ENOMEM; 236 LogRelFunc(("could not allocate memory for root inode path\n")); 237 goto fail2; 238 } 239 240 sf_i->path->u16Length = 1; 241 sf_i->path->u16Size = 2; 242 sf_i->path->String.utf8[0] = '/'; 243 sf_i->path->String.utf8[1] = 0; 244 sf_i->force_reread = 0; 245 246 err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0); 247 if (err) { 248 LogFunc(("could not stat root of share\n")); 249 goto fail3; 250 } 251 252 sb->s_magic = 0xface; 253 sb->s_blocksize = 1024; 269 254 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 3) 270 271 272 273 274 275 276 277 # 278 279 # 280 281 # 282 #endif 283 255 /* Required for seek/sendfile. 256 * 257 * Must by less than or equal to INT64_MAX despite the fact that the 258 * declaration of this variable is unsigned long long. See determination 259 * of 'loff_t max' in fs/read_write.c / do_sendfile(). I don't know the 260 * correct limit but MAX_LFS_FILESIZE (8TB-1 on 32-bit boxes) takes the 261 * page cache into account and is the suggested limit. */ 262 #if defined MAX_LFS_FILESIZE 263 sb->s_maxbytes = MAX_LFS_FILESIZE; 264 #else 265 sb->s_maxbytes = 0x7fffffffffffffffULL; 266 #endif 267 #endif 268 sb->s_op = &sf_super_ops; 284 269 285 270 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25) 286 iroot = iget_locked(sb, 0); 287 #else 288 iroot = iget(sb, 0); 289 #endif 290 if (!iroot) 291 { 292 err = -ENOMEM; /* XXX */ 293 LogFunc(("could not get root inode\n")); 294 goto fail3; 295 } 296 297 if (sf_init_backing_dev(sf_g)) 298 { 299 err = -EINVAL; 300 LogFunc(("could not init bdi\n")); 271 iroot = iget_locked(sb, 0); 272 #else 273 iroot = iget(sb, 0); 274 #endif 275 if (!iroot) { 276 err = -ENOMEM; /* XXX */ 277 LogFunc(("could not get root inode\n")); 278 goto fail3; 279 } 280 281 if (sf_init_backing_dev(sf_g)) { 282 err = -EINVAL; 283 LogFunc(("could not init bdi\n")); 301 284 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25) 302 303 #endif 304 305 306 307 308 285 unlock_new_inode(iroot); 286 #endif 287 goto fail4; 288 } 289 290 sf_init_inode(sf_g, iroot, &fsinfo); 291 SET_INODE_INFO(iroot, sf_i); 309 292 310 293 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 25) 311 294 unlock_new_inode(iroot); 312 295 #endif 313 296 314 297 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) 315 droot = d_make_root(iroot); 316 #else 317 droot = d_alloc_root(iroot); 318 #endif 319 if (!droot) 320 { 321 err = -ENOMEM; /* XXX */ 322 LogFunc(("d_alloc_root failed\n")); 298 droot = d_make_root(iroot); 299 #else 300 droot = d_alloc_root(iroot); 301 #endif 302 if (!droot) { 303 err = -ENOMEM; /* XXX */ 304 LogFunc(("d_alloc_root failed\n")); 323 305 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) 324 325 #endif 326 327 328 329 330 331 332 333 fail5:334 335 336 fail4:337 338 339 340 fail3:341 342 343 fail2:344 345 346 fail1:347 348 349 fail0:350 306 fInodePut = false; 307 #endif 308 goto fail5; 309 } 310 311 sb->s_root = droot; 312 SET_GLOB_INFO(sb, sf_g); 313 return 0; 314 315 fail5: 316 sf_done_backing_dev(sf_g); 317 318 fail4: 319 if (fInodePut) 320 iput(iroot); 321 322 fail3: 323 kfree(sf_i->path); 324 325 fail2: 326 kfree(sf_i); 327 328 fail1: 329 sf_glob_free(sf_g); 330 331 fail0: 332 return err; 351 333 } 352 334 353 335 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) 354 static struct super_block * 355 sf_read_super_24(struct super_block *sb, void *data,int flags)356 { 357 358 359 360 361 362 363 364 336 static struct super_block *sf_read_super_24(struct super_block *sb, void *data, 337 int flags) 338 { 339 int err; 340 341 TRACE(); 342 err = sf_read_super_aux(sb, data, flags); 343 if (err) 344 return NULL; 345 346 return sb; 365 347 } 366 348 #endif … … 371 353 static void sf_clear_inode(struct inode *inode) 372 354 { 373 374 375 376 377 378 379 380 381 382 383 355 struct sf_inode_info *sf_i; 356 357 TRACE(); 358 sf_i = GET_INODE_INFO(inode); 359 if (!sf_i) 360 return; 361 362 BUG_ON(!sf_i->path); 363 kfree(sf_i->path); 364 kfree(sf_i); 365 SET_INODE_INFO(inode, NULL); 384 366 } 385 367 #else 386 368 static void sf_evict_inode(struct inode *inode) 387 369 { 388 389 390 391 392 # 393 394 # 395 396 # 397 398 399 400 401 402 403 404 405 370 struct sf_inode_info *sf_i; 371 372 TRACE(); 373 truncate_inode_pages(&inode->i_data, 0); 374 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) 375 clear_inode(inode); 376 #else 377 end_writeback(inode); 378 #endif 379 380 sf_i = GET_INODE_INFO(inode); 381 if (!sf_i) 382 return; 383 384 BUG_ON(!sf_i->path); 385 kfree(sf_i->path); 386 kfree(sf_i); 387 SET_INODE_INFO(inode, NULL); 406 388 } 407 389 #endif … … 421 403 static void sf_put_super(struct super_block *sb) 422 404 { 423 424 425 426 427 428 405 struct sf_glob_info *sf_g; 406 407 sf_g = GET_GLOB_INFO(sb); 408 BUG_ON(!sf_g); 409 sf_done_backing_dev(sf_g); 410 sf_glob_free(sf_g); 429 411 } 430 412 431 413 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) 432 static int sf_statfs(struct super_block *sb, STRUCT_STATFS * stat)433 { 434 435 } 436 #else 437 static int sf_statfs(struct dentry *dentry, STRUCT_STATFS * stat)438 { 439 440 414 static int sf_statfs(struct super_block *sb, STRUCT_STATFS * stat) 415 { 416 return sf_get_volume_info(sb, stat); 417 } 418 #else 419 static int sf_statfs(struct dentry *dentry, STRUCT_STATFS * stat) 420 { 421 struct super_block *sb = dentry->d_inode->i_sb; 422 return sf_get_volume_info(sb, stat); 441 423 } 442 424 #endif … … 445 427 { 446 428 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 23) 447 struct sf_glob_info *sf_g; 448 struct sf_inode_info *sf_i; 449 struct inode *iroot; 450 SHFLFSOBJINFO fsinfo; 451 int err; 452 453 sf_g = GET_GLOB_INFO(sb); 454 BUG_ON(!sf_g); 455 if (data && data[0] != 0) 456 { 457 struct vbsf_mount_info_new *info = 458 (struct vbsf_mount_info_new *)data; 459 if ( info->signature[0] == VBSF_MOUNT_SIGNATURE_BYTE_0 460 && info->signature[1] == VBSF_MOUNT_SIGNATURE_BYTE_1 461 && info->signature[2] == VBSF_MOUNT_SIGNATURE_BYTE_2) 462 { 463 sf_g->uid = info->uid; 464 sf_g->gid = info->gid; 465 sf_g->ttl = info->ttl; 466 sf_g->dmode = info->dmode; 467 sf_g->fmode = info->fmode; 468 sf_g->dmask = info->dmask; 469 sf_g->fmask = info->fmask; 470 } 471 } 472 473 iroot = ilookup(sb, 0); 474 if (!iroot) 475 return -ENOSYS; 476 477 sf_i = GET_INODE_INFO(iroot); 478 err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0); 479 BUG_ON(err != 0); 480 sf_init_inode(sf_g, iroot, &fsinfo); 481 /*unlock_new_inode(iroot);*/ 482 return 0; 483 #else 484 return -ENOSYS; 485 #endif 486 } 487 488 static struct super_operations sf_super_ops = 489 { 429 struct sf_glob_info *sf_g; 430 struct sf_inode_info *sf_i; 431 struct inode *iroot; 432 SHFLFSOBJINFO fsinfo; 433 int err; 434 435 sf_g = GET_GLOB_INFO(sb); 436 BUG_ON(!sf_g); 437 if (data && data[0] != 0) { 438 struct vbsf_mount_info_new *info = 439 (struct vbsf_mount_info_new *)data; 440 if (info->signature[0] == VBSF_MOUNT_SIGNATURE_BYTE_0 441 && info->signature[1] == VBSF_MOUNT_SIGNATURE_BYTE_1 442 && info->signature[2] == VBSF_MOUNT_SIGNATURE_BYTE_2) { 443 sf_g->uid = info->uid; 444 sf_g->gid = info->gid; 445 sf_g->ttl = info->ttl; 446 sf_g->dmode = info->dmode; 447 sf_g->fmode = info->fmode; 448 sf_g->dmask = info->dmask; 449 sf_g->fmask = info->fmask; 450 } 451 } 452 453 iroot = ilookup(sb, 0); 454 if (!iroot) 455 return -ENOSYS; 456 457 sf_i = GET_INODE_INFO(iroot); 458 err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0); 459 BUG_ON(err != 0); 460 sf_init_inode(sf_g, iroot, &fsinfo); 461 /*unlock_new_inode(iroot); */ 462 return 0; 463 #else 464 return -ENOSYS; 465 #endif 466 } 467 468 static struct super_operations sf_super_ops = { 490 469 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) 491 492 #else 493 470 .clear_inode = sf_clear_inode, 471 #else 472 .evict_inode = sf_evict_inode, 494 473 #endif 495 474 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) 496 .read_inode= sf_read_inode,497 #endif 498 .put_super= sf_put_super,499 .statfs= sf_statfs,500 .remount_fs= sf_remount_fs475 .read_inode = sf_read_inode, 476 #endif 477 .put_super = sf_put_super, 478 .statfs = sf_statfs, 479 .remount_fs = sf_remount_fs 501 480 }; 502 481 … … 504 483 static DECLARE_FSTYPE(vboxsf_fs_type, "vboxsf", sf_read_super_24, 0); 505 484 #else 506 static int 507 sf_read_super_26(struct super_block *sb, void *data, int flags) 508 { 509 int err; 510 511 TRACE();512 err = sf_read_super_aux(sb, data, flags); 513 if (err) 514 printk(KERN_DEBUG "sf_read_super_aux err=%d\n", err); 515 516 return err; 517 } 518 519 # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) 520 static struct super_block *sf_get_sb(struct file_system_type *fs_type, int flags,521 const char *dev_name,void *data)522 { 523 524 525 } 526 # 485 static int sf_read_super_26(struct super_block *sb, void *data, int flags) 486 { 487 int err; 488 489 TRACE(); 490 err = sf_read_super_aux(sb, data, flags); 491 if (err) 492 printk(KERN_DEBUG "sf_read_super_aux err=%d\n", err); 493 494 return err; 495 } 496 497 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) 498 static struct super_block *sf_get_sb(struct file_system_type *fs_type, 499 int flags, const char *dev_name, 500 void *data) 501 { 502 TRACE(); 503 return get_sb_nodev(fs_type, flags, data, sf_read_super_26); 504 } 505 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) 527 506 static int sf_get_sb(struct file_system_type *fs_type, int flags, 528 529 { 530 531 532 } 533 # 507 const char *dev_name, void *data, struct vfsmount *mnt) 508 { 509 TRACE(); 510 return get_sb_nodev(fs_type, flags, data, sf_read_super_26, mnt); 511 } 512 #else 534 513 static struct dentry *sf_mount(struct file_system_type *fs_type, int flags, 535 const char *dev_name, void *data) 536 { 537 TRACE(); 538 return mount_nodev(fs_type, flags, data, sf_read_super_26); 539 } 540 # endif 541 542 static struct file_system_type vboxsf_fs_type = 543 { 544 .owner = THIS_MODULE, 545 .name = "vboxsf", 546 # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) 547 .get_sb = sf_get_sb, 548 # else 549 .mount = sf_mount, 550 # endif 551 .kill_sb = kill_anon_super 514 const char *dev_name, void *data) 515 { 516 TRACE(); 517 return mount_nodev(fs_type, flags, data, sf_read_super_26); 518 } 519 #endif 520 521 static struct file_system_type vboxsf_fs_type = { 522 .owner = THIS_MODULE, 523 .name = "vboxsf", 524 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) 525 .get_sb = sf_get_sb, 526 #else 527 .mount = sf_mount, 528 #endif 529 .kill_sb = kill_anon_super 552 530 }; 553 531 #endif … … 556 534 static int follow_symlinks = 0; 557 535 module_param(follow_symlinks, int, 0); 558 MODULE_PARM_DESC(follow_symlinks, "Let host resolve symlinks rather than showing them"); 536 MODULE_PARM_DESC(follow_symlinks, 537 "Let host resolve symlinks rather than showing them"); 559 538 #endif 560 539 … … 562 541 static int __init init(void) 563 542 { 564 int rcVBox; 565 int rcRet = 0; 566 int err; 567 568 TRACE(); 569 570 if (sizeof(struct vbsf_mount_info_new) > PAGE_SIZE) 571 { 572 printk(KERN_ERR 573 "Mount information structure is too large %lu\n" 574 "Must be less than or equal to %lu\n", 575 (unsigned long)sizeof (struct vbsf_mount_info_new), 576 (unsigned long)PAGE_SIZE); 577 return -EINVAL; 578 } 579 580 err = register_filesystem(&vboxsf_fs_type); 581 if (err) 582 { 583 LogFunc(("register_filesystem err=%d\n", err)); 584 return err; 585 } 586 587 rcVBox = VbglR0HGCMInit(); 588 if (RT_FAILURE(rcVBox)) 589 { 590 LogRelFunc(("VbglR0HGCMInit failed, rc=%d\n", rcVBox)); 591 rcRet = -EPROTO; 592 goto fail0; 593 } 594 595 rcVBox = VbglR0SfConnect(&client_handle); 596 if (RT_FAILURE(rcVBox)) 597 { 598 LogRelFunc(("VbglR0SfConnect failed, rc=%d\n", rcVBox)); 599 rcRet = -EPROTO; 600 goto fail1; 601 } 602 603 rcVBox = VbglR0SfSetUtf8(&client_handle); 604 if (RT_FAILURE(rcVBox)) 605 { 606 LogRelFunc(("VbglR0SfSetUtf8 failed, rc=%d\n", rcVBox)); 607 rcRet = -EPROTO; 608 goto fail2; 609 } 610 543 int rcVBox; 544 int rcRet = 0; 545 int err; 546 547 TRACE(); 548 549 if (sizeof(struct vbsf_mount_info_new) > PAGE_SIZE) { 550 printk(KERN_ERR 551 "Mount information structure is too large %lu\n" 552 "Must be less than or equal to %lu\n", 553 (unsigned long)sizeof(struct vbsf_mount_info_new), 554 (unsigned long)PAGE_SIZE); 555 return -EINVAL; 556 } 557 558 err = register_filesystem(&vboxsf_fs_type); 559 if (err) { 560 LogFunc(("register_filesystem err=%d\n", err)); 561 return err; 562 } 563 564 rcVBox = VbglR0HGCMInit(); 565 if (RT_FAILURE(rcVBox)) { 566 LogRelFunc(("VbglR0HGCMInit failed, rc=%d\n", rcVBox)); 567 rcRet = -EPROTO; 568 goto fail0; 569 } 570 571 rcVBox = VbglR0SfConnect(&client_handle); 572 if (RT_FAILURE(rcVBox)) { 573 LogRelFunc(("VbglR0SfConnect failed, rc=%d\n", rcVBox)); 574 rcRet = -EPROTO; 575 goto fail1; 576 } 577 578 rcVBox = VbglR0SfSetUtf8(&client_handle); 579 if (RT_FAILURE(rcVBox)) { 580 LogRelFunc(("VbglR0SfSetUtf8 failed, rc=%d\n", rcVBox)); 581 rcRet = -EPROTO; 582 goto fail2; 583 } 611 584 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) 612 if (!follow_symlinks) 613 { 614 rcVBox = VbglR0SfSetSymlinks(&client_handle); 615 if (RT_FAILURE(rcVBox)) 616 { 617 printk(KERN_WARNING 618 "vboxsf: Host unable to show symlinks, rc=%d\n", 619 rcVBox); 620 } 621 } 622 #endif 623 624 printk(KERN_DEBUG 625 "vboxsf: Successfully loaded version " VBOX_VERSION_STRING 626 " (interface " RT_XSTR(VMMDEV_VERSION) ")\n"); 627 628 return 0; 629 630 fail2: 631 VbglR0SfDisconnect(&client_handle); 632 633 fail1: 634 VbglR0HGCMTerminate(); 635 636 fail0: 637 unregister_filesystem(&vboxsf_fs_type); 638 return rcRet; 585 if (!follow_symlinks) { 586 rcVBox = VbglR0SfSetSymlinks(&client_handle); 587 if (RT_FAILURE(rcVBox)) { 588 printk(KERN_WARNING 589 "vboxsf: Host unable to show symlinks, rc=%d\n", 590 rcVBox); 591 } 592 } 593 #endif 594 595 printk(KERN_DEBUG 596 "vboxsf: Successfully loaded version " VBOX_VERSION_STRING 597 " (interface " RT_XSTR(VMMDEV_VERSION) ")\n"); 598 599 return 0; 600 601 fail2: 602 VbglR0SfDisconnect(&client_handle); 603 604 fail1: 605 VbglR0HGCMTerminate(); 606 607 fail0: 608 unregister_filesystem(&vboxsf_fs_type); 609 return rcRet; 639 610 } 640 611 641 612 static void __exit fini(void) 642 613 { 643 644 645 646 647 614 TRACE(); 615 616 VbglR0SfDisconnect(&client_handle); 617 VbglR0HGCMTerminate(); 618 unregister_filesystem(&vboxsf_fs_type); 648 619 } 649 620
Note:
See TracChangeset
for help on using the changeset viewer.