From 8fb7098371b9c7d75fff0841384518ebce695d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 29 Jun 2009 09:35:39 +0000 Subject: [PATCH] Cut down on the required number of syscalls by using the new Haiku API for reading/writing attributes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31311 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/coreutils/src/copy.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/bin/coreutils/src/copy.c b/src/bin/coreutils/src/copy.c index a80e493091..e3b464c115 100644 --- a/src/bin/coreutils/src/copy.c +++ b/src/bin/coreutils/src/copy.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -147,35 +148,49 @@ copy_attributes(int fromFd, int toFd) return -1; while ((dirent = fs_read_attr_dir(attributes)) != NULL) { - attr_info info; + struct stat stat; off_t pos = 0; + int attrFromFD = fs_open_attr(fromFd, dirent->d_name, 0, O_RDONLY); + int attrToFD; - if (fs_stat_attr(fromFd, dirent->d_name, &info) != 0) + if (attrFromFD < 0) continue; + if (fstat(attrFromFD, &stat) != 0) { + close(attrFromFD); + continue; + } + + attrToFD = fs_open_attr(toFd, dirent->d_name, stat.st_type, + O_WRONLY | O_TRUNC | O_CREAT); + if (attrToFD < 0) { + close(attrFromFD); + continue; + } + while (true) { ssize_t bytesRead, bytesWritten; - bytesRead = fs_read_attr(fromFd, dirent->d_name, info.type, pos, - buffer, sizeof(buffer)); + bytesRead = read_pos(attrFromFD, pos, buffer, sizeof(buffer)); if (bytesRead < 0) { fprintf(stderr, "error reading attribute '%s'", dirent->d_name); break; } - bytesWritten = fs_write_attr(toFd, dirent->d_name, info.type, pos, - buffer, bytesRead); + bytesWritten = write_pos(attrToFD, pos, buffer, bytesRead); if (bytesWritten != bytesRead) { fprintf(stderr, "error writing attribute '%s'", dirent->d_name); break; } pos += bytesWritten; - info.size -= bytesWritten; + stat.st_size -= bytesWritten; - if (info.size <= 0) + if (stat.st_size <= 0) break; } + close(attrToFD); + close(attrFromFD); } fs_close_attr_dir(attributes);