From a13ee0c82ceff5d4e65f8641c8d9aef06231cdf6 Mon Sep 17 00:00:00 2001 From: jpandre Date: Fri, 27 Mar 2009 08:36:07 +0000 Subject: [PATCH] Fed the free spaces in context for calls from security API --- include/ntfs-3g/volume.h | 2 ++ libntfs-3g/security.c | 13 ++++++++++--- libntfs-3g/volume.c | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/ntfs-3g/volume.h b/include/ntfs-3g/volume.h index 5b726fbf..069932f2 100644 --- a/include/ntfs-3g/volume.h +++ b/include/ntfs-3g/volume.h @@ -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 */ diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 5a0a52cc..0a28fc26 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -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()) diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index d2fa4a27..a3625073 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -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); +}