[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-ntfs-cvs
Subject: [Linux-NTFS-cvs] CVS: linux-ntfs/ntfstools ntfslabel.c,1.11,1.12
From: "Matthew J. Fanto" <mattjf () users ! sourceforge ! net>
Date: 2002-04-28 21:20:29
[Download RAW message or body]
Changes by: mattjf
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv10655/ntfstools
Modified Files:
ntfslabel.c
Log Message:
ntfslabel - Coverted stoucs to ntfs_mbstoucs()
- code cleanup
- better error checking
unistr.c - removed size_t casts from ntfs_mbstoucs()
Index: ntfslabel.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfslabel.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- ntfslabel.c 27 Apr 2002 19:49:10 -0000 1.11
+++ ntfslabel.c 28 Apr 2002 21:20:27 -0000 1.12
@@ -7,4 +7,5 @@
* Copyright (c) 2002 Matthew J. Fanto
* Copyright (c) 2002 Anton Altaparmakov
+ * Copyright (c) 2002 Richard Russon
*
* This utility will display/change the label on an NTFS partition.
@@ -43,4 +44,5 @@
#include "mft.h"
#include "attrib.h"
+#include "unistr.h"
const char *EXEC_NAME = "ntfslabel";
@@ -63,6 +65,9 @@
const char *val, const __u32 val_len);
-int
-main(int argc, char **argv)
+int stoucs(uchar_t * dest, const char *src, int maxlen);
+
+
+
+int main(int argc, char **argv)
{
char *locale;
@@ -91,4 +96,6 @@
}
+
+
/**
* print_label - display the current label on a device
@@ -99,6 +106,5 @@
* it is not.
**/
-void
-print_label(const char *dev)
+void print_label(const char *dev)
{
@@ -126,5 +132,5 @@
}
-int stoucs(uchar_t * dest, const char *src, int maxlen);
+
/**
@@ -150,6 +156,5 @@
int label_len;
- printf("now changing label - FIXME: Not implemented yet!\n");
-
+
/*First we need to make sure the device is not mounted */
err = ntfs_check_if_mounted(dev, &mnt_flags);
@@ -158,8 +163,8 @@
if (errno == ENODEV) {
printf("Error: %s is not a valid block device!\n", dev);
- exit(1);
- }
-
+ }
+ exit(1);
}
+
if(mnt_flags == NTFS_MF_MOUNTED)
{
@@ -189,6 +194,5 @@
if (!ctx) {
- printf
- ("Failed to allocate attribute search context!\n");
+ printf("Failed to allocate attribute search context!\n");
exit(1);
}
@@ -196,13 +200,11 @@
- if (ntfs_lookup_attr
- (AT_VOLUME_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
+ if (ntfs_lookup_attr(AT_VOLUME_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
printf("$VOLUME_NAME attribute not found?!?\n");
exit(1);
}
-
-
a = ctx->attr;
+
if (a->non_resident) {
printf("Error: Attribute $VOLUME_NAME must be resident!\n");
@@ -210,8 +212,27 @@
}
- new_label = malloc((label_len + 1) * sizeof(uchar_t));
- label_len = stoucs(new_label,label,(label_len + 1) *
- sizeof(uchar_t)) * sizeof(uchar_t);
+ new_label = malloc((label_len + 1 ) * sizeof(uchar_t));
+ label_len = ntfs_mbstoucs(label,(label_len + 1) *
+ sizeof(char), &new_label,(label_len + 1) * sizeof(uchar_t));
+ if (label_len == -1)
+ {
+ printf("Unable to convert string to Unicode!\n");
+
+ if(errno == EINVAL)
+ printf("Invalid argument!\n");
+ else if (errno == EILSEQ)
+ printf("Input string cannot be represented as Unicode!\n");
+ else if (errno == ENAMETOOLONG)
+ printf("Destination buffer is too small!");
+ else if (errno == ENOMEM)
+ printf("Not enough memory to allocate destination buffer!\n");
+
+ exit(1);
+
+ }
+
+ label_len = label_len * sizeof(uchar_t);
+
if (resize_resident_attribute_value(mrec, a, label_len)) {
printf("Error: Cannot resize resident attribute!\n");
@@ -223,26 +244,6 @@
-
- /*if (modify_resident_attr_in_mft_record(mrec,
- AT_VOLUME_NAME, NULL, 0, 0, 0, 0, (char *)label,label_len)) {
-
- printf("Error: Cannot modify resident attribute!\n");
- exit(1);
- }*/
-
-
-
if (ntfs_write_mft_record(vol, mref, mrec)) {
printf("Error: Cannot write MFT Record to disk!\n");
-
- if (errno == EINVAL)
- printf("EINVAL\n");
- if (errno == EBADF)
- printf("EBADF\n");
- if (errno == ESPIPE)
- printf("ESPIPE\n");
- if (errno == EIO)
- printf("EIO\n");
-
exit(1);
}
@@ -286,21 +287,3 @@
-
-
-int stoucs(uchar_t * dest, const char *src, int maxlen)
-{
- char c;
- int i;
-
- /* Need two bytes for null terminator. */
- maxlen -= 2;
- for (i = 0; i < maxlen; i++) {
- c = src[i];
- if (!c)
- break;
- dest[i] = cpu_to_le16(c);
- }
- dest[i] = cpu_to_le16('\0');
- return i;
-}
_______________________________________________
Linux-NTFS-cvs mailing list
Linux-NTFS-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-ntfs-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic