btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / shared / AttributeUtilities.cpp
blob76f6f27eb4750ee9dfb911877fa4fdf598309312
1 /*
2 * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2016, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
5 */
8 #include "AttributeUtilities.h"
10 #include <fs_attr.h>
11 #include <Node.h>
12 #include <StorageDefs.h>
15 static const int kCopyBufferSize = 64 * 1024;
16 // 64 KB
19 namespace BPrivate {
22 status_t
23 CopyAttributes(BNode& source, BNode& destination)
25 char attrName[B_ATTR_NAME_LENGTH];
26 while (source.GetNextAttrName(attrName) == B_OK) {
27 // get attr info
28 attr_info attrInfo;
29 status_t status = source.GetAttrInfo(attrName, &attrInfo);
30 if (status != B_OK)
31 return status;
33 // copy the attribute
34 char buffer[kCopyBufferSize];
35 off_t offset = 0;
36 off_t bytesLeft = attrInfo.size;
38 // Go at least once through the loop, so that an empty attribute will be
39 // created as well
40 do {
41 size_t toRead = kCopyBufferSize;
42 if ((off_t)toRead > bytesLeft)
43 toRead = bytesLeft;
45 // read
46 ssize_t bytesRead = source.ReadAttr(attrName, attrInfo.type,
47 offset, buffer, toRead);
48 if (bytesRead < 0)
49 return bytesRead;
51 // write
52 ssize_t bytesWritten = destination.WriteAttr(attrName,
53 attrInfo.type, offset, buffer, bytesRead);
54 if (bytesWritten < 0)
55 return bytesWritten;
57 bytesLeft -= bytesRead;
58 offset += bytesRead;
59 } while (bytesLeft > 0);
61 return B_OK;
65 } // namespace BPrivate