From ebb38c4b1c61e968d3a0b861a30c661351f9564c Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 7 Nov 2012 14:15:53 +0100 Subject: [PATCH] API cleanup of const arguments. - Replaced 'ntfschar*' parameters with 'const ntfschar*' where appropriate (the function does not need to modify the string). - Replaced some instances of 'u8*' and 'char*' read-only buffer arguments with 'const u8*' and 'const char*'. --- include/ntfs-3g/attrib.h | 15 ++++++++------- include/ntfs-3g/dir.h | 11 ++++++----- include/ntfs-3g/volume.h | 3 ++- libntfs-3g/attrib.c | 19 +++++++++---------- libntfs-3g/dir.c | 27 +++++++++++++++------------ libntfs-3g/volume.c | 4 ++-- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/include/ntfs-3g/attrib.h b/include/ntfs-3g/attrib.h index 67fb957d..1979ba68 100644 --- a/include/ntfs-3g/attrib.h +++ b/include/ntfs-3g/attrib.h @@ -320,17 +320,18 @@ int ntfs_attr_force_non_resident(ntfs_attr *na); extern int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size); extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, u8 *val, u32 size, + const ntfschar *name, u8 name_len, const u8 *val, u32 size, ATTR_FLAGS flags); extern int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, - ATTR_FLAGS flags); + const ntfschar *name, u8 name_len, VCN lowest_vcn, + int dataruns_size, ATTR_FLAGS flags); extern int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx); extern int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, u8 *val, s64 size); + ntfschar *name, u8 name_len, const u8 *val, s64 size); extern int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask); + const ntfschar *name, u8 name_len, ATTR_FLAGS flags, + ATTR_FLAGS mask); extern int ntfs_attr_rm(ntfs_attr *na); extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size); @@ -379,7 +380,7 @@ extern s64 ntfs_get_attribute_value(const ntfs_volume *vol, extern void ntfs_attr_name_free(char **name); extern char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len); extern int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, - ntfschar *name, u32 name_len); + const ntfschar *name, u32 name_len); extern int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len); extern s64 ntfs_attr_get_free_bits(ntfs_attr *na); @@ -388,7 +389,7 @@ extern int ntfs_attr_data_read(ntfs_inode *ni, char *buf, size_t size, off_t offset); extern int ntfs_attr_data_write(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, - char *buf, size_t size, off_t offset); + const char *buf, size_t size, off_t offset); #endif /* defined _NTFS_ATTRIB_H */ diff --git a/include/ntfs-3g/dir.h b/include/ntfs-3g/dir.h index 56e76fe7..a99c1ae0 100644 --- a/include/ntfs-3g/dir.h +++ b/include/ntfs-3g/dir.h @@ -68,17 +68,18 @@ extern void ntfs_inode_update_mbsname(ntfs_inode *dir_ni, const char *name, extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, const char *pathname); extern ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, mode_t type); + const ntfschar *name, u8 name_len, mode_t type); extern ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, mode_t type, dev_t dev); + const ntfschar *name, u8 name_len, mode_t type, dev_t dev); extern ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, ntfschar *target, int target_len); + const ntfschar *name, u8 name_len, const ntfschar *target, + int target_len); extern int ntfs_check_empty_dir(ntfs_inode *ni); extern int ntfs_delete(ntfs_volume *vol, const char *path, - ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, + ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len); -extern int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, +extern int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len); /* diff --git a/include/ntfs-3g/volume.h b/include/ntfs-3g/volume.h index 9d62d668..67f738b1 100644 --- a/include/ntfs-3g/volume.h +++ b/include/ntfs-3g/volume.h @@ -302,7 +302,8 @@ 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_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len); +extern int ntfs_volume_rename(ntfs_volume *vol, const ntfschar *label, + int label_len); extern int ntfs_set_shown_files(ntfs_volume *vol, BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files); diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 210dcbc3..c116d9ad 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3739,8 +3739,8 @@ int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size) * EIO - I/O error occurred or damaged filesystem. */ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, u8 *val, u32 size, - ATTR_FLAGS data_flags) + const ntfschar *name, u8 name_len, const u8 *val, + u32 size, ATTR_FLAGS data_flags) { ntfs_attr_search_ctx *ctx; u32 length; @@ -3871,7 +3871,7 @@ put_err_out: * EIO - I/O error occurred or damaged filesystem. */ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, + const ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, ATTR_FLAGS flags) { ntfs_attr_search_ctx *ctx; @@ -4154,7 +4154,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) * On success return 0. On error return -1 with errno set to the error code. */ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, u8 *val, s64 size) + ntfschar *name, u8 name_len, const u8 *val, s64 size) { u32 attr_rec_size; int err, i, offset; @@ -4349,8 +4349,8 @@ err_out: * Change an attribute flag */ -int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, - ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask) +int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, + u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask) { ntfs_attr_search_ctx *ctx; int res; @@ -6661,9 +6661,8 @@ exit: * Returns the amount of data written, negative if there was an error */ -int ntfs_attr_data_write(ntfs_inode *ni, - ntfschar *stream_name, int stream_name_len, - char *buf, size_t size, off_t offset) +int ntfs_attr_data_write(ntfs_inode *ni, ntfschar *stream_name, + int stream_name_len, const char *buf, size_t size, off_t offset) { ntfs_attr *na = NULL; int res, total = 0; @@ -6695,7 +6694,7 @@ exit: } -int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, +int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, const ntfschar *name, u32 name_len) { ntfs_attr_search_ctx *ctx; diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 0be826d0..2539586c 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1482,8 +1482,8 @@ err_out: * on error with errno set to the error code. */ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, mode_t type, dev_t dev, - ntfschar *target, int target_len) + const ntfschar *name, u8 name_len, mode_t type, dev_t dev, + const ntfschar *target, int target_len) { ntfs_inode *ni; int rollback_data = 0, rollback_sd = 0; @@ -1752,7 +1752,7 @@ err_out: * Some wrappers around __ntfs_create() ... */ -ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, ntfschar *name, +ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type) { if (type != S_IFREG && type != S_IFDIR && type != S_IFIFO && @@ -1764,7 +1764,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, ntfschar *name, } ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, mode_t type, dev_t dev) + const ntfschar *name, u8 name_len, mode_t type, dev_t dev) { if (type != S_IFCHR && type != S_IFBLK) { ntfs_log_error("Invalid arguments.\n"); @@ -1774,7 +1774,8 @@ ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, } ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, - ntfschar *name, u8 name_len, ntfschar *target, int target_len) + const ntfschar *name, u8 name_len, const ntfschar *target, + int target_len) { if (!target || !target_len) { ntfs_log_error("%s: Invalid argument (%p, %d)\n", __FUNCTION__, @@ -1849,7 +1850,8 @@ no_hardlink: * Return 0 on success or -1 on error with errno set to the error code. */ int ntfs_delete(ntfs_volume *vol, const char *pathname, - ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) + ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, + u8 name_len) { ntfs_attr_search_ctx *actx = NULL; FILE_NAME_ATTR *fn = NULL; @@ -2140,7 +2142,7 @@ err_out: * * Return 0 on success or -1 on error with errno set to the error code. */ -static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, +static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len, FILE_NAME_TYPE_FLAGS nametype) { FILE_NAME_ATTR *fn = NULL; @@ -2226,7 +2228,8 @@ err_out: return -1; } -int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) +int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, + u8 name_len) { return (ntfs_link_i(ni, dir_ni, name, name_len, FILE_NAME_POSIX)); } @@ -2448,7 +2451,7 @@ int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, */ static int set_namespace(ntfs_inode *ni, ntfs_inode *dir_ni, - ntfschar *name, int len, + const ntfschar *name, int len, FILE_NAME_TYPE_FLAGS nametype) { ntfs_attr_search_ctx *actx; @@ -2522,9 +2525,9 @@ static int set_namespace(ntfs_inode *ni, ntfs_inode *dir_ni, */ static int set_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, - ntfschar *shortname, int shortlen, - ntfschar *longname, int longlen, - ntfschar *deletename, int deletelen, BOOL existed) + const ntfschar *shortname, int shortlen, + const ntfschar *longname, int longlen, + const ntfschar *deletename, int deletelen, BOOL existed) { unsigned int linkcount; ntfs_volume *vol; diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index 7ec6d6e4..cc3d4a05 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -1832,7 +1832,7 @@ int ntfs_volume_get_free_space(ntfs_volume *vol) * * Change the label on the volume @vol to @label. */ -int ntfs_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len) +int ntfs_volume_rename(ntfs_volume *vol, const ntfschar *label, int label_len) { ntfs_attr *na; char *old_vol_name; @@ -1867,7 +1867,7 @@ int ntfs_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len) /* The volume name attribute does not exist. Need to add it. */ if (ntfs_attr_add(vol->vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0, - (u8*) label, label_len)) + (const u8*) label, label_len)) { err = errno; ntfs_log_perror("Encountered error while adding "