Lines Matching +full:translate +full:- +full:errno
2 * utils.c - Part of the Linux-NTFS project.
4 * Copyright (c) 2002-2005 Richard Russon
5 * Copyright (c) 2003-2006 Anton Altaparmakov
7 * Copyright (c) 2005-2007 Yura Pakhuchiy
8 * Copyright (c) 2014 Jean-Pierre Andre
23 * along with this program (in the main directory of the Linux-NTFS
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #include <errno.h>
109 " F) ntfsmount: Mount the volume read-only by using the 'ro' mount option.\n";
122 "(NOT to us!) that init scripts kill ntfsmount or mount.ntfs-fuse during\n"
149 * linux-ntfs's ntfs_mbstoucs has different semantics, so we emulate it with
150 * ntfs-3g's.
156 errno = EINVAL; in ntfs_mbstoucs_libntfscompat()
157 return -1; in ntfs_mbstoucs_libntfscompat()
161 * specify a preallocated buffer while libntfs-3g's always in ntfs_mbstoucs_libntfscompat()
176 tmpstr_len = -1; in ntfs_mbstoucs_libntfscompat()
197 * utils_valid_device - Perform some safety checks on the device, before start
217 errno = EINVAL; in utils_valid_device()
221 if (stat(name, &st) == -1) { in utils_valid_device()
222 if (errno == ENOENT) in utils_valid_device()
255 * utils_mount_volume - Mount an NTFS volume
262 errno = EINVAL; in utils_mount_volume()
268 * libntfs-3g does not have the 'force' flag in ntfs_mount_flags. in utils_mount_volume()
275 * libntfs-3g only has safety check number 2. The dirty flag is simply in utils_mount_volume()
287 if (errno == EINVAL) in utils_mount_volume()
289 else if (errno == EIO) in utils_mount_volume()
291 else if (errno == EPERM) in utils_mount_volume()
293 else if (errno == EOPNOTSUPP) in utils_mount_volume()
295 else if (errno == EBUSY) in utils_mount_volume()
297 else if (errno == ENXIO) in utils_mount_volume()
303 * libntfs-3g does not record whether the volume log file was dirty in utils_mount_volume()
306 if (vol->flags & VOLUME_IS_DIRTY) { in utils_mount_volume()
319 * utils_parse_size - Convert a string representing a size
347 errno = EINVAL; in utils_parse_size()
354 if (result < 0 || errno == ERANGE) { in utils_parse_size()
374 case '-': case 0: in utils_parse_size()
381 if ((suffix[0] != '-') && (suffix[0] != 0)) { in utils_parse_size()
382 ntfs_log_error("Invalid number '%.*s'.\n", (int)(suffix - value + 1), value); in utils_parse_size()
393 * utils_parse_range - Convert a string representing a range of numbers
398 * Read a string of the form n-m. If the lower end is missing, zero will be
411 errno = EINVAL; in utils_parse_range()
415 middle = strchr(string, '-'); in utils_parse_range()
437 ntfs_log_debug("Range '%s' = %lld - %lld\n", string, (long long)a, in utils_parse_range()
446 * find_attribute - Find an attribute of the given type
462 errno = EINVAL; in find_attribute()
472 return ctx->attr; in find_attribute()
476 * find_first_attribute - Find the first attribute of a given type
495 errno = EINVAL; in find_first_attribute()
541 errno = EINVAL; in utils_inode_get_name()
545 vol = inode->vol; in utils_inode_get_name()
558 //ntfs_log_debug("i = %d, inode = %p (%lld)\n", i, inode, inode->mft_no); in utils_inode_get_name()
563 attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset)); in utils_inode_get_name()
565 if (attr->file_name_type > name_space) { //XXX find the ... in utils_inode_get_name()
569 name_space = attr->file_name_type; in utils_inode_get_name()
570 parent = le64_to_cpu(attr->parent_directory); in utils_inode_get_name()
577 if (ntfs_ucstombs(attr->file_name, attr->file_name_length, in utils_inode_get_name()
580 ntfs_log_error("Couldn't translate filename to current locale.\n"); in utils_inode_get_name()
585 long long)inode->mft_no); in utils_inode_get_name()
618 for (i = max_path; i >= 0; i--) { in utils_inode_get_name()
622 len = snprintf(buffer + offset, bufsize - offset, "%c%s", PATH_SEP, names[i]); in utils_inode_get_name()
623 if (len >= (bufsize - offset)) { in utils_inode_get_name()
652 errno = EINVAL; in utils_attr_get_name()
656 attrdef = ntfs_attr_find_in_attrdef(vol, attr->type); in utils_attr_get_name()
659 namelen = ntfs_ucsnlen(attrdef->name, sizeof(attrdef->name)); in utils_attr_get_name()
660 if (ntfs_ucstombs(attrdef->name, namelen, &name, 0) < 0) { in utils_attr_get_name()
661 ntfs_log_error("Couldn't translate attribute type to " in utils_attr_get_name()
668 ntfs_log_error("Unknown attribute type 0x%02x\n", le32_to_cpu(attr->type)); in utils_attr_get_name()
677 if (!attr->name_length) { in utils_attr_get_name()
682 bufsize -= len; in utils_attr_get_name()
685 namelen = attr->name_length; in utils_attr_get_name()
687 + le16_to_cpu(attr->name_offset)), in utils_attr_get_name()
689 ntfs_log_error("Couldn't translate attribute name to current " in utils_attr_get_name()
708 * utils_cluster_in_use - Determine if a cluster is in use
725 * -1 Error occurred
730 static long long bmplcn = -(sizeof(buffer) << 3); in utils_cluster_in_use()
735 errno = EINVAL; in utils_cluster_in_use()
736 return -1; in utils_cluster_in_use()
743 attr = ntfs_attr_open(vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0); in utils_cluster_in_use()
746 return -1; in utils_cluster_in_use()
751 bmplcn = lcn & (~((sizeof(buffer) << 3) - 1)); in utils_cluster_in_use()
757 return -1; in utils_cluster_in_use()
765 byte = (lcn >> 3) & (sizeof(buffer) - 1); in utils_cluster_in_use()
774 * utils_mftrec_in_use - Determine if a MFT Record is in use
788 * -1 Error occurred
793 static s64 bmpmref = -(sizeof(buffer) << 3) - 1; /* Which bit of $BITMAP is in the buffer */ in utils_mftrec_in_use()
799 errno = EINVAL; in utils_mftrec_in_use()
800 return -1; in utils_mftrec_in_use()
810 bmpmref = mref & (~((sizeof(buffer) << 3) - 1)); in utils_mftrec_in_use()
812 if (ntfs_attr_pread(vol->mftbmp_na, (bmpmref>>3), sizeof(buffer), buffer) < 0) { in utils_mftrec_in_use()
814 return -1; in utils_mftrec_in_use()
821 byte = (mref >> 3) & (sizeof(buffer) - 1); in utils_mftrec_in_use()
837 return -1; in __metadata()
838 if ((vol->major_ver == 3) && (num == FILE_Extend)) in __metadata()
845 * utils_is_metadata - Determine if an inode represents a metadata file
848 * A handful of files in the volume contain filesystem data - metadata.
854 * -1 Error occurred
865 errno = EINVAL; in utils_is_metadata()
866 return -1; in utils_is_metadata()
869 vol = inode->vol; in utils_is_metadata()
871 return -1; in utils_is_metadata()
873 num = inode->mft_no; in utils_is_metadata()
877 file = inode->mrec; in utils_is_metadata()
878 if (file && (file->base_mft_record != 0)) { in utils_is_metadata()
879 num = MREF_LE(file->base_mft_record); in utils_is_metadata()
884 rec = find_first_attribute(AT_FILE_NAME, inode->mrec); in utils_is_metadata()
886 return -1; in utils_is_metadata()
889 attr = (FILE_NAME_ATTR *)((char *)rec + le16_to_cpu(rec->value_offset)); in utils_is_metadata()
891 num = MREF_LE(attr->parent_directory); in utils_is_metadata()
899 * utils_dump_mem - Display a block of memory in hex and ascii
905 * Display a block of memory in a tradition hex-dump manner.
941 ntfs_log_debug(" -"); in utils_dump_mem()
973 errno = EINVAL; in mft_get_search_ctx()
979 ctx->mft_num = -1; in mft_get_search_ctx()
980 ctx->vol = vol; in mft_get_search_ctx()
992 if (ctx->inode) in mft_put_search_ctx()
993 ntfs_inode_close(ctx->inode); in mft_put_search_ctx()
1009 errno = EINVAL; in mft_next_record()
1010 return -1; in mft_next_record()
1013 if (ctx->inode) { in mft_next_record()
1014 ntfs_inode_close(ctx->inode); in mft_next_record()
1015 ctx->inode = NULL; in mft_next_record()
1018 nr_mft_records = ctx->vol->mft_na->initialized_size >> in mft_next_record()
1019 ctx->vol->mft_record_size_bits; in mft_next_record()
1021 for (ctx->mft_num++; (s64)ctx->mft_num < nr_mft_records; ctx->mft_num++) { in mft_next_record()
1024 ctx->flags_match = 0; in mft_next_record()
1025 in_use = utils_mftrec_in_use(ctx->vol, (MFT_REF) ctx->mft_num); in mft_next_record()
1026 if (in_use == -1) { in mft_next_record()
1028 (unsigned long long)ctx->mft_num); in mft_next_record()
1029 return -1; in mft_next_record()
1033 ctx->flags_match |= FEMR_IN_USE; in mft_next_record()
1035 ctx->inode = ntfs_inode_open(ctx->vol, (MFT_REF) ctx->mft_num); in mft_next_record()
1036 if (ctx->inode == NULL) { in mft_next_record()
1042 r = ntfs_file_record_read(ctx->vol, in mft_next_record()
1043 (MFT_REF) ctx->mft_num, &mrec, NULL); in mft_next_record()
1044 if (r || !mrec || !mrec->base_mft_record) in mft_next_record()
1047 (long long)ctx->mft_num); in mft_next_record()
1050 mrec->base_mft_record); in mft_next_record()
1053 (long long)ctx->mft_num, in mft_next_record()
1060 attr10 = find_first_attribute(AT_STANDARD_INFORMATION, ctx->inode->mrec); in mft_next_record()
1061 attr20 = find_first_attribute(AT_ATTRIBUTE_LIST, ctx->inode->mrec); in mft_next_record()
1062 attr80 = find_first_attribute(AT_DATA, ctx->inode->mrec); in mft_next_record()
1065 ctx->flags_match |= FEMR_BASE_RECORD; in mft_next_record()
1067 ctx->flags_match |= FEMR_NOT_BASE_RECORD; in mft_next_record()
1070 ctx->flags_match |= FEMR_BASE_RECORD; in mft_next_record()
1073 ctx->flags_match |= FEMR_FILE; in mft_next_record()
1075 if (ctx->flags_search & FEMR_DIR) { in mft_next_record()
1076 attr_ctx = ntfs_attr_get_search_ctx(ctx->inode, NULL); in mft_next_record()
1079 ctx->flags_match |= FEMR_DIR; in mft_next_record()
1084 return -1; in mft_next_record()
1088 switch (utils_is_metadata(ctx->inode)) { in mft_next_record()
1089 case 1: ctx->flags_match |= FEMR_METADATA; break; in mft_next_record()
1090 case 0: ctx->flags_match |= FEMR_NOT_METADATA; break; in mft_next_record()
1092 ctx->flags_match |= FEMR_NOT_METADATA; break; in mft_next_record()
1093 //ntfs_log_error("Error reading inode %lld.\n", ctx->mft_num); in mft_next_record()
1094 //return -1; in mft_next_record()
1100 ctx->flags_match |= FEMR_NOT_IN_USE; in mft_next_record()
1102 ctx->inode = (ntfs_inode*)calloc(1, sizeof(*ctx->inode)); in mft_next_record()
1103 if (!ctx->inode) { in mft_next_record()
1105 return -1; in mft_next_record()
1108 ctx->inode->mft_no = ctx->mft_num; in mft_next_record()
1109 ctx->inode->vol = ctx->vol; in mft_next_record()
1110 ctx->inode->mrec = ntfs_malloc(ctx->vol->mft_record_size); in mft_next_record()
1111 if (!ctx->inode->mrec) { in mft_next_record()
1112 free(ctx->inode); // == ntfs_inode_close in mft_next_record()
1113 return -1; in mft_next_record()
1116 mft = ntfs_attr_open(ctx->vol->mft_ni, AT_DATA, in mft_next_record()
1121 return -1; in mft_next_record()
1124 …if (ntfs_attr_pread(mft, ctx->vol->mft_record_size * ctx->mft_num, ctx->vol->mft_record_size, ctx-… in mft_next_record()
1126 (unsigned long long) ctx->mft_num); in mft_next_record()
1129 return -1; in mft_next_record()
1135 if (ctx->flags_match & ctx->flags_search) { in mft_next_record()
1139 if (ntfs_inode_close(ctx->inode)) { in mft_next_record()
1141 (unsigned long long)ctx->mft_num); in mft_next_record()
1142 return -errno; in mft_next_record()
1145 ctx->inode = NULL; in mft_next_record()
1148 return (ctx->inode == NULL); in mft_next_record()
1154 * Translate formats for older Windows
1157 * specifications (%lld, %llx, etc). We have to translate them
1186 && (*f != '*') && (*f != '-')) in ntfs_utils_reformat()
1213 * Translate paths to files submitted from Windows
1215 * Translate Windows directory separators to Unix ones
1218 * NULL if there was an error, with errno set
1232 errno = ENOMEM; in ntfs_utils_unix_path()