Changeset 221 for branches/samba-3.3.x/source/libsmb/libsmb_stat.c
- Timestamp:
- May 24, 2009, 7:17:10 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.3.x/source/libsmb/libsmb_stat.c
r206 r221 156 156 return -1; 157 157 } 158 158 159 159 if (!user || user[0] == (char)0) { 160 160 user = talloc_strdup(frame, smbc_getUser(context)); … … 301 301 302 302 } 303 304 305 /* 306 * Routine to obtain file system information given a path 307 */ 308 int 309 SMBC_statvfs_ctx(SMBCCTX *context, 310 char *path, 311 struct statvfs *st) 312 { 313 int ret; 314 bool bIsDir; 315 struct stat statbuf; 316 SMBCFILE * pFile; 317 318 /* Determine if the provided path is a file or a folder */ 319 if (SMBC_stat_ctx(context, path, &statbuf) < 0) { 320 return -1; 321 } 322 323 /* Is it a file or a directory? */ 324 if (S_ISDIR(statbuf.st_mode)) { 325 /* It's a directory. */ 326 if ((pFile = SMBC_opendir_ctx(context, path)) == NULL) { 327 return -1; 328 } 329 bIsDir = true; 330 } else if (S_ISREG(statbuf.st_mode)) { 331 /* It's a file. */ 332 if ((pFile = SMBC_open_ctx(context, path, 333 O_RDONLY, 0)) == NULL) { 334 return -1; 335 } 336 bIsDir = false; 337 } else { 338 /* It's neither a file nor a directory. Not supported. */ 339 errno = ENOSYS; 340 return -1; 341 } 342 343 /* Now we have an open file handle, so just use SMBC_fstatvfs */ 344 ret = SMBC_fstatvfs_ctx(context, pFile, st); 345 346 /* Close the file or directory */ 347 if (bIsDir) { 348 SMBC_closedir_ctx(context, pFile); 349 } else { 350 SMBC_close_ctx(context, pFile); 351 } 352 353 return ret; 354 } 355 356 357 /* 358 * Routine to obtain file system information given an fd 359 */ 360 361 int 362 SMBC_fstatvfs_ctx(SMBCCTX *context, 363 SMBCFILE *file, 364 struct statvfs *st) 365 { 366 unsigned long flags = 0; 367 uint32 fs_attrs = 0; 368 struct cli_state *cli = file->srv->cli; 369 370 371 /* Initialize all fields (at least until we actually use them) */ 372 memset(st, 0, sizeof(*st)); 373 374 /* 375 * The state of each flag is such that the same bits are unset as 376 * would typically be unset on a local file system on a POSIX OS. Thus 377 * the bit is on, for example, only for case-insensitive file systems 378 * since most POSIX file systems are case sensitive and fstatvfs() 379 * would typically return zero in these bits on such a local file 380 * system. 381 */ 382 383 /* See if the server has UNIX CIFS support */ 384 if (! SERVER_HAS_UNIX_CIFS(cli)) { 385 SMB_BIG_UINT total_allocation_units; 386 SMB_BIG_UINT caller_allocation_units; 387 SMB_BIG_UINT actual_allocation_units; 388 SMB_BIG_UINT sectors_per_allocation_unit; 389 SMB_BIG_UINT bytes_per_sector; 390 391 /* Nope. If size data is available... */ 392 if (cli_get_fs_full_size_info(cli, 393 &total_allocation_units, 394 &caller_allocation_units, 395 &actual_allocation_units, 396 §ors_per_allocation_unit, 397 &bytes_per_sector)) { 398 399 /* ... then provide it */ 400 st->f_bsize = 401 (unsigned long) bytes_per_sector; 402 #if HAVE_FRSIZE 403 st->f_frsize = 404 (unsigned long) sectors_per_allocation_unit; 405 #endif 406 st->f_blocks = 407 (fsblkcnt_t) total_allocation_units; 408 st->f_bfree = 409 (fsblkcnt_t) actual_allocation_units; 410 } 411 412 flags |= SMBC_VFS_FEATURE_NO_UNIXCIFS; 413 } else { 414 uint32 optimal_transfer_size; 415 uint32 block_size; 416 SMB_BIG_UINT total_blocks; 417 SMB_BIG_UINT blocks_available; 418 SMB_BIG_UINT user_blocks_available; 419 SMB_BIG_UINT total_file_nodes; 420 SMB_BIG_UINT free_file_nodes; 421 SMB_BIG_UINT fs_identifier; 422 423 /* Has UNIXCIFS. If POSIX filesystem info is available... */ 424 if (cli_get_posix_fs_info(cli, 425 &optimal_transfer_size, 426 &block_size, 427 &total_blocks, 428 &blocks_available, 429 &user_blocks_available, 430 &total_file_nodes, 431 &free_file_nodes, 432 &fs_identifier)) { 433 434 /* ... then what's provided here takes precedence. */ 435 st->f_bsize = 436 (unsigned long) block_size; 437 st->f_blocks = 438 (fsblkcnt_t) total_blocks; 439 st->f_bfree = 440 (fsblkcnt_t) blocks_available; 441 st->f_bavail = 442 (fsblkcnt_t) user_blocks_available; 443 st->f_files = 444 (fsfilcnt_t) total_file_nodes; 445 st->f_ffree = 446 (fsfilcnt_t) free_file_nodes; 447 #if HAVE_FSID_INT 448 st->f_fsid = 449 (unsigned long) fs_identifier; 450 #endif 451 } 452 } 453 454 /* See if the share is case sensitive */ 455 if (!cli_get_fs_attr_info(cli, &fs_attrs)) { 456 /* 457 * We can't determine the case sensitivity of 458 * the share. We have no choice but to use the 459 * user-specified case sensitivity setting. 460 */ 461 if (! smbc_getOptionCaseSensitive(context)) { 462 flags |= SMBC_VFS_FEATURE_CASE_INSENSITIVE; 463 } 464 } else { 465 if (! (fs_attrs & FILE_CASE_SENSITIVE_SEARCH)) { 466 flags |= SMBC_VFS_FEATURE_CASE_INSENSITIVE; 467 } 468 } 469 470 /* See if DFS is supported */ 471 if ((cli->capabilities & CAP_DFS) && cli->dfsroot) { 472 flags |= SMBC_VFS_FEATURE_DFS; 473 } 474 475 #if HAVE_STATVFS_F_FLAG 476 st->f_flag = flags; 477 #elif HAVE_STATVFS_F_FLAGS 478 st->f_flags = flags; 479 #endif 480 481 return 0; 482 }
Note:
See TracChangeset
for help on using the changeset viewer.