Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv18456/libntfs
Modified Files:
volume.c
Log Message:
Cleanup ntfslabel, write a man page for it, integrate it all in the distribution properly, silence output from ntfs_mount() (conditional on running configure with --enable-debug), update all docs accordingly. Add Rich and Matt to AUTHORS.
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -U2 -r1.19 -r1.20
--- volume.c 11 Apr 2002 23:10:59 -0000 1.19
+++ volume.c 12 Apr 2002 15:23:47 -0000 1.20
@@ -38,4 +38,5 @@
#include "attrib.h"
#include "mft.h"
+#include "debug.h"
/**
@@ -167,13 +168,13 @@
/* Allocate the boot sector structure. */
if (!(bs = (NTFS_BOOT_SECTOR *)malloc(sizeof(NTFS_BOOT_SECTOR)))) {
- puts(FAILED);
+ Vputs(FAILED);
perror("Error allocating memory for bootsector");
errno = ENOMEM;
goto error_exit;
}
- printf("Reading bootsector... ");
+ Vprintf("Reading bootsector... ");
if ((vol->fd = open(name, ro ? O_RDONLY: O_RDWR)) == -1) {
int eo = errno;
- puts(FAILED);
+ Vputs(FAILED);
perror("Error opening partition file");
errno = eo;
@@ -184,5 +185,5 @@
if (br != 1) {
int eo = errno;
- puts(FAILED);
+ Vputs(FAILED);
#define ESTR "Error reading bootsector"
if (br == -1) {
@@ -200,5 +201,5 @@
goto error_exit;
}
- puts(OK);
+ Vputs(OK);
#ifdef DEBUG
if (!is_boot_sector_ntfs(bs, 0)) {
@@ -287,7 +288,7 @@
#endif
/* Start with $Mft. */
- printf("Loading $Mft... ");
+ Vprintf("Loading $Mft... ");
if (!(mb = (MFT_RECORD *)malloc(vol->mft_record_size))) {
- puts(FAILED);
+ Vputs(FAILED);
perror("Error allocating memory for $Mft");
errno = ENOMEM;
@@ -298,5 +299,5 @@
vol->mft_lcn << vol->cluster_size_bits);
if (br != 1) {
- puts(FAILED);
+ Vputs(FAILED);
#define ESTR "Error reading $Mft"
if (br == -1)
@@ -312,5 +313,5 @@
}
if (is_baad_record(mb)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "Error: Incomplete multi sector "
"transfer detected in $Mft.\nCannot "
@@ -320,5 +321,5 @@
}
if (!is_mft_recordp(mb)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "Error: Invalid mft record for $Mft.\n"
"Cannot handle this yet. )-:\n");
@@ -332,5 +333,5 @@
if (p2n(ctx.attr) < p2n(mb) ||
(char*)ctx.attr > (char*)mb + vol->mft_record_size) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "Error: corrupt mft record for $Mft.\n"
"Cannot handle this yet. )-:\n");
@@ -340,5 +341,5 @@
ctx.is_first = TRUE;
if (!find_attr($BITMAP, NULL, 0, 0, NULL, 0, NULL, 0, &ctx)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "$bitmap attribute not found in $Mft?!?\n");
errno = EIO;
@@ -349,5 +350,5 @@
l = get_attribute_value_length(a);
if (!l) {
- puts(OK);
+ Vputs(OK);
puts("Error: $bitmap in $Mft has zero length! T'is weird!");
errno = EIO;
@@ -356,5 +357,5 @@
vol->mft_bitmap = (__u8*)malloc(l);
if (!vol->mft_bitmap) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Not enough memory to load bitmap attribute from $Mft.");
errno = ENOMEM;
@@ -363,5 +364,5 @@
/* Read in the bitmap attribute value into the buffer. */
if (l != get_attribute_value(vol, mb, a, vol->mft_bitmap)) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Amount of data read does not correspond to expected "
"length!");
@@ -384,5 +385,5 @@
ctx.is_first = TRUE;
if (!find_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, &ctx)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "$DATA attribute not found in $Mft?!?\n");
errno = EIO;
@@ -394,5 +395,5 @@
/* The $DATA attribute of the $Mft has to be non-resident. */
if (!a->non_resident) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "$Mft $DATA attribute is resident!?!\n");
errno = EINVAL;
@@ -402,5 +403,5 @@
vol->mft_runlist = decompress_run_list(a);
if (!vol->mft_runlist) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "Error decompressing run list from $Mft $DATA"
" attribute.\n");
@@ -408,13 +409,13 @@
goto error_exit;
}
- puts(OK);
+ Vputs(OK);
/* Done with the $Mft mft record. */
free(mb);
mb = NULL;
/* Now load the bitmap from $Bitmap. */
- printf("Loading $Bitmap... ");
+ Vprintf("Loading $Bitmap... ");
mref = (MFT_REF)FILE_$Bitmap;
if (err = __read_file_record(vol, &mref, &mb, NULL)) {
- puts(FAILED);
+ Vputs(FAILED);
errno = -err;
goto error_exit;
@@ -424,5 +425,5 @@
/* Find the bitmap (it is in the $DATA attribute). */
if (!find_first_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, &ctx)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "bitmap attribute not found in $Bitmap?!?\n");
errno = EIO;
@@ -433,5 +434,5 @@
l = get_attribute_value_length(a);
if (!l) {
- puts(OK);
+ Vputs(OK);
puts("Error: bitmap in $Bitmap has zero length! T'is weird!");
errno = EIO;
@@ -440,5 +441,5 @@
vol->lcn_bitmap = (__u8*)malloc(l);
if (!vol->lcn_bitmap) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Not enough memory to load $Bitmap.");
errno = ENOMEM;
@@ -447,5 +448,5 @@
/* Read in the bitmap attribute value into the buffer. */
if (l != get_attribute_value(vol, mb, a, vol->lcn_bitmap)) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Amount of data read does not correspond to expected "
"length!");
@@ -454,12 +455,12 @@
}
/* Done with the $BitMap mft record. */
- puts(OK);
+ Vputs(OK);
free(mb);
mb = NULL;
/* Now load the upcase table from $UpCase. */
- printf("Loading $UpCase... ");
+ Vprintf("Loading $UpCase... ");
mref = (MFT_REF)FILE_$UpCase;
if (err = __read_file_record(vol, &mref, &mb, NULL)) {
- puts(FAILED);
+ Vputs(FAILED);
errno = -err;
goto error_exit;
@@ -469,5 +470,5 @@
/* Find the bitmap (it is in the $DATA attribute). */
if (!find_first_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, &ctx)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "$DATA attribute not found in $UpCase?!?\n");
errno = EIO;
@@ -478,5 +479,5 @@
l = get_attribute_value_length(a);
if (!l) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Error: $DATA in $UpCase has zero length! T'is weird!");
errno = EIO;
@@ -488,5 +489,5 @@
* characters. */
if (l & ~0x1ffffffffULL) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Error: Upcase table is too big (max 32-bit allowed).");
errno = EINVAL;
@@ -496,5 +497,5 @@
vol->upcase = (uchar_t*)malloc(l);
if (!vol->upcase) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Not enough memory to load $UpCase.");
errno = ENOMEM;
@@ -503,5 +504,5 @@
/* Read in the $DATA attribute value into the buffer. */
if (l != get_attribute_value(vol, mb, a, (__u8*)vol->upcase)) {
- puts(FAILED);
+ Vputs(FAILED);
puts("Amount of data read does not correspond to expected "
"length!");
@@ -510,13 +511,13 @@
}
/* Done with the $UpCase mft record. */
- puts(OK);
+ Vputs(OK);
free(mb);
mb = NULL;
/* Now load $Volume and set the version information and flags in the
* vol structure accordingly. */
- printf("Loading $Volume... ");
+ Vprintf("Loading $Volume... ");
mref = (MFT_REF)FILE_$Volume;
if (err = __read_file_record(vol, &mref, &mb, NULL)) {
- puts(FAILED);
+ Vputs(FAILED);
errno = -err;
goto error_exit;
@@ -527,5 +528,5 @@
if (!find_first_attr($VOLUME_INFORMATION, NULL, 0, 0, NULL, 0, NULL, 0,
&ctx)) {
- puts(FAILED);
+ Vputs(FAILED);
fprintf(stderr, "$VOLUME_INFORMATION attribute not found in "
"$Volume?!?\n");
@@ -560,13 +561,10 @@
defined using cpu_to_le16() macro and hence are consistent. */
vol->flags = vinf->flags;
- /* Phew! Done. */
-
- /* FIXME: Need to initialise vol->vol_name as well. */
+ /* Find the $VOLUME_NAME attribute. */
memset(&ctx, 0, sizeof(attr_search_context));
ctx.mrec = mb;
- /* Find the $VOLUME_NAME attribute. */
if (!find_first_attr($VOLUME_NAME, NULL, 0, 0, NULL, 0, NULL, 0,
- &ctx)) {
- puts(FAILED);
+ &ctx)) {
+ Vputs(FAILED);
fprintf(stderr, "$VOLUME_NAME attribute not found in "
"$Volume?!?\n");
@@ -583,15 +581,19 @@
}
/* Get a pointer to the value of the attribute. */
- vol->vol_name = malloc ((a->value_length/2)+1);
- if(!vol->vol_name)
- {
- printf("Unable to allocate memory!\n");
- exit(1);
- }
- vname = (uchar_t *)(VOLUME_NAME*)(le16_to_cpu(a->value_offset) + (char*)a);
- for (j = 0; j < (a->value_length/2); j++) { vol->vol_name[j] = vname[j]; }
- vol->vol_name[a->value_length/2] = 0;
+ vol->vol_name = malloc(le32_to_cpu(a->value_length) / 2 + 1);
+ if (!vol->vol_name) {
+ fprintf(stderr, "Error: Unable to allocate memory for volume "
+ "name!\n");
+ errno = ENOMEM;
+ goto error_exit;
+ }
+ vname = (uchar_t*)(le16_to_cpu(a->value_offset) + (char*)a);
+ u = le32_to_cpu(a->value_length) / 2;
+ for (j = 0; j < u; j++) {
+ vol->vol_name[j] = le16_to_cpu(vname[j]);
+ }
+ vol->vol_name[u] = '\0';
- puts(OK);
+ Vputs(OK);
free(mb);
mb = NULL;
|