Fed the free spaces in context for calls from security API

N2009_11_14_FIXES
jpandre 2009-03-27 08:36:07 +00:00
parent 86c1f05336
commit a13ee0c82c
3 changed files with 39 additions and 3 deletions

View File

@ -263,6 +263,8 @@ extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags);
extern int ntfs_volume_error(int err);
extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err);
extern int ntfs_volume_get_free_space(ntfs_volume *vol);
extern int ntfs_set_locale(void);
#endif /* defined _NTFS_VOLUME_H */

View File

@ -4733,7 +4733,8 @@ struct SECURITY_API *ntfs_initialize_file_security(const char *device,
if (vol) {
scapi = (struct SECURITY_API*)
ntfs_malloc(sizeof(struct SECURITY_API));
if (scapi) {
if (!ntfs_volume_get_free_space(vol)
&& scapi) {
scapi->magic = MAGIC_API;
scapi->seccache = (struct PERMISSIONS_CACHE*)NULL;
scx = &scapi->security;
@ -4745,8 +4746,14 @@ struct SECURITY_API *ntfs_initialize_file_security(const char *device,
/* accept no mapping and no $Secure */
ntfs_build_mapping(scx,(const char*)NULL);
ntfs_open_secure(vol);
} else
errno = ENOMEM;
} else {
if (scapi)
free(scapi);
else
errno = ENOMEM;
mnt = ntfs_umount(vol,FALSE);
scapi = (struct SECURITY_API*)NULL;
}
}
} else
if (getuid())

View File

@ -1564,3 +1564,30 @@ int ntfs_set_locale(void)
return 0;
}
/*
* Feed the counts of free clusters and free mft records
*/
int ntfs_volume_get_free_space(ntfs_volume *vol)
{
ntfs_attr *na;
int ret;
ret = -1; /* default return */
vol->free_clusters = ntfs_attr_get_free_bits(vol->lcnbmp_na);
if (vol->free_clusters < 0) {
ntfs_log_perror("Failed to read NTFS $Bitmap");
} else {
na = vol->mftbmp_na;
vol->free_mft_records = ntfs_attr_get_free_bits(na);
if (vol->free_mft_records >= 0)
vol->free_mft_records += (na->allocated_size - na->data_size) << 3;
if (vol->free_mft_records < 0)
ntfs_log_perror("Failed to calculate free MFT records");
else
ret = 0;
}
return (ret);
}