* Added some more types that are printed as string in catattr, and listattr.

* catattr no longer pretends B_MIME_STRING to be of type string.
* Added message output for both listattr, and catattr.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34438 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-02 10:18:42 +00:00
parent a9cf57cff5
commit 8247d95f63
3 changed files with 70 additions and 22 deletions
+1 -1
View File
@@ -23,7 +23,6 @@ AddResources checkitout : checkitout.rdef ;
StdBinCommands StdBinCommands
badblocks.c badblocks.c
cal.c cal.c
catattr.cpp
chop.c chop.c
clear.c clear.c
clockconfig.c clockconfig.c
@@ -77,6 +76,7 @@ StdBinCommands
# standard commands that need libbe.so # standard commands that need libbe.so
StdBinCommands StdBinCommands
beep.cpp beep.cpp
catattr.cpp
checkfs.cpp checkfs.cpp
clipboard.cpp clipboard.cpp
df.cpp df.cpp
+50 -20
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2005, Stephan Aßmus, [email protected]. * Copyright 2005, Stephan Aßmus, [email protected].
* Copyright 2004, Axel Dörfler, [email protected]. * Copyright 2004-2009, Axel Dörfler, [email protected].
* Copyright 2002, Sebastian Nozzi. * Copyright 2002, Sebastian Nozzi.
* *
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
@@ -20,8 +20,7 @@
#include <unistd.h> #include <unistd.h>
/** Used to present the characters in the raw data view */ /*! Used to present the characters in the raw data view */
static void static void
putCharOrDot(uchar c) putCharOrDot(uchar c)
{ {
@@ -29,12 +28,11 @@ putCharOrDot(uchar c)
} }
/** Dumps the contents of the attribute in the form of /*! Dumps the contents of the attribute in the form of
* raw data. This view is used for the type B_RAW_DATA_TYPE, raw data. This view is used for the type B_RAW_DATA_TYPE,
* for custom types and for any type that is not directly for custom types and for any type that is not directly
* supported by the utility "addattr" supported by the utility "addattr"
*/ */
static void static void
dumpRawData(const char *buffer, size_t size) dumpRawData(const char *buffer, size_t size)
{ {
@@ -82,8 +80,11 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false)
// limit size of the attribute, only the first 64k will make it on screen // limit size of the attribute, only the first 64k will make it on screen
off_t size = info.size; off_t size = info.size;
if (size > 64 * 1024) bool cut = false;
if (size > 64 * 1024) {
size = 64 * 1024; size = 64 * 1024;
cut = true;
}
char* buffer = (char*)malloc(size); char* buffer = (char*)malloc(size);
if (!buffer) { if (!buffer) {
@@ -98,7 +99,8 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false)
} }
if (bytesRead != size) { if (bytesRead != size) {
fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); fprintf(stderr, "Could only read %ld bytes from attribute!\n",
bytesRead);
free(buffer); free(buffer);
return B_ERROR; return B_ERROR;
} }
@@ -112,21 +114,28 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false)
// check for write error // check for write error
if (written < bytesRead) { if (written < bytesRead) {
if (written >= 0) { if (written >= 0) {
fprintf(stderr, "Could only write %ld bytes to stream!\n", written); fprintf(stderr, "Could only write %ld bytes to stream!\n",
written);
written = B_ERROR; written = B_ERROR;
} else } else {
fprintf(stderr, "Failed to write to stream: %s\n", strerror(written)); fprintf(stderr, "Failed to write to stream: %s\n",
strerror(written));
}
break; break;
} }
// read next chunk of data at pos // read next chunk of data at pos
pos += bytesRead; pos += bytesRead;
bytesRead = fs_read_attr(fd, attribute, info.type, pos, buffer, size); bytesRead = fs_read_attr(fd, attribute, info.type, pos, buffer,
size);
// check for read error // check for read error
if (bytesRead < size && pos + bytesRead < info.size) { if (bytesRead < size && pos + bytesRead < info.size) {
if (bytesRead >= 0) if (bytesRead >= 0) {
fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); fprintf(stderr, "Could only read %ld bytes from "
else "attribute!\n", bytesRead);
fprintf(stderr, "Failed to read from attribute: %s\n", strerror(bytesRead)); } else {
fprintf(stderr, "Failed to read from attribute: %s\n",
strerror(bytesRead));
}
written = B_ERROR; written = B_ERROR;
break; break;
} }
@@ -172,10 +181,31 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false)
printf("%s : bool : %d\n", fileName, *((unsigned char *)buffer)); printf("%s : bool : %d\n", fileName, *((unsigned char *)buffer));
break; break;
case B_STRING_TYPE: case B_STRING_TYPE:
case B_MIME_STRING_TYPE:
printf("%s : string : %s\n", fileName, buffer); printf("%s : string : %s\n", fileName, buffer);
break; break;
case B_MIME_STRING_TYPE:
case 'MSIG':
case 'MSDC':
case 'MPTH':
printf("%s : '%c%c%c%c' : %s\n", fileName,
(int)((info.type >> 24) & 0xff),
(int)((info.type >> 16) & 0xff),
(int)((info.type >> 8) & 0xff), (int)(info.type & 0xff),
buffer);
break;
case B_MESSAGE_TYPE:
{
BMessage message;
if (!cut && message.Unflatten(buffer) == B_OK) {
printf("%s : message :\n", fileName);
message.PrintToStream();
break;
}
// supposed to fall through
}
default: default:
// The rest of the attributes types are displayed as raw data // The rest of the attributes types are displayed as raw data
printf("%s : raw_data : \n", fileName); printf("%s : raw_data : \n", fileName);
+19 -1
View File
@@ -62,9 +62,12 @@ show_attr_contents(BNode& node, const char* attribute, const attr_info& info)
// limit size of the attribute, only the first kLimit byte will make it on // limit size of the attribute, only the first kLimit byte will make it on
// screen // screen
int kLimit = 256; int kLimit = 256;
bool cut = false;
off_t size = info.size; off_t size = info.size;
if (size > kLimit) if (size > kLimit) {
size = kLimit; size = kLimit;
cut = true;
}
char buffer[kLimit]; char buffer[kLimit];
ssize_t bytesRead = node.ReadAttr(attribute, info.type, 0, buffer, size); ssize_t bytesRead = node.ReadAttr(attribute, info.type, 0, buffer, size);
@@ -110,9 +113,24 @@ show_attr_contents(BNode& node, const char* attribute, const attr_info& info)
break; break;
case B_STRING_TYPE: case B_STRING_TYPE:
case B_MIME_STRING_TYPE: case B_MIME_STRING_TYPE:
case 'MSIG':
case 'MSDC':
case 'MPTH':
printf("%s\n", buffer); printf("%s\n", buffer);
break; break;
case B_MESSAGE_TYPE:
{
BMessage message;
if (!cut && message.Unflatten(buffer) == B_OK) {
putchar('\n');
message.PrintToStream();
putchar('\n');
break;
}
// supposed to fall through
}
default: default:
// The rest of the attributes types are displayed as raw data // The rest of the attributes types are displayed as raw data
putchar('\n'); putchar('\n');