2 ** copy_attrs.h - copy BeFS attributes from one file to another
4 ** Jan. 11, 1998 Chris Herborth (chrish@qnx.com)
6 ** This code is donated to the PUBLIC DOMAIN. You can use, abuse, modify,
7 ** redistribute, steal, or otherwise manipulate this code. No restrictions
8 ** at all. If you laugh at this code, you can't use it.
11 #include <support/Errors.h>
14 #define ASSERT(cond) assert(cond)
16 #define ASSERT(cond) ((void)0)
25 #include <kernel/fs_attr.h>
28 #include "copy_attrs.h"
30 static const char *rcs_version_id
= "$Id$";
32 /* ----------------------------------------------------------------------
33 ** Copy file attributes from src_file to dst_file.
36 status_t
copy_attrs( const char *dst_file
, const char *src_file
)
39 status_t retval
= B_OK
;
41 struct dirent
*fa_ent
= NULL
;
43 struct attr_info fa_info
;
44 off_t read_bytes
, wrote_bytes
;
46 ASSERT( dst_file
!= NULL
);
47 ASSERT( src_file
!= NULL
);
49 /* Attempt to open the files.
51 src_fd
= open( src_file
, O_RDONLY
);
53 return B_FILE_NOT_FOUND
;
56 dst_fd
= open( dst_file
, O_WRONLY
);
59 return B_FILE_NOT_FOUND
;
62 /* Read the attributes, and write them to the destination file.
64 fa_dir
= fs_fopen_attr_dir( src_fd
);
65 if( fa_dir
== NULL
) {
70 fa_ent
= fs_read_attr_dir( fa_dir
);
71 while( fa_ent
!= NULL
) {
72 retval
= fs_stat_attr( src_fd
, fa_ent
->d_name
, &fa_info
);
73 if( retval
!= B_OK
) {
74 /* TODO: Print warning message?
79 if( fa_info
.size
> (off_t
)UINT_MAX
) {
80 /* TODO: That's too big. Print a warning message? You could
81 ** copy it in chunks...
86 if( fa_info
.size
> (off_t
)0 ) {
87 buff
= malloc( (size_t)fa_info
.size
);
89 /* TODO: Can't allocate memory for this attribute. Warning?
94 read_bytes
= fs_read_attr( src_fd
, fa_ent
->d_name
, fa_info
.type
,
95 0, buff
, fa_info
.size
);
96 if( read_bytes
!= fa_info
.size
) {
97 /* TODO: Couldn't read entire attribute. Warning?
102 wrote_bytes
= fs_write_attr( dst_fd
, fa_ent
->d_name
, fa_info
.type
,
103 0, buff
, fa_info
.size
);
104 if( wrote_bytes
!= fa_info
.size
) {
105 /* TODO: Couldn't write entire attribute. Warning?
116 /* Read the next entry.
119 fa_ent
= fs_read_attr_dir( fa_dir
);