]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/asingle.c
Writing metadata xattr on directories with sticky bit set, FR#94
[netatalk.git] / bin / megatron / asingle.c
index 0d2faea90bc1a10ea04248119942382a7897a8f8..9ba3918b6a0a2dfa65b7d6de7b6e022003e74f50 100644 (file)
@@ -1,5 +1,4 @@
 /*
- * $Id: asingle.c,v 1.10 2005-04-28 20:49:19 bfernhomberg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <time.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
+
 #include <atalk/adouble.h>
 #include <netatalk/endian.h>
 #include "asingle.h"
        following globals; therefore this module can only be used
        for one of the two functions at a time.
  */
-struct single_file_data {
+static struct single_file_data {
     int                        filed;
     char               path[ MAXPATHLEN + 1];
     struct ad_entry    entry[ ADEID_MAX ];
 }              single;
 
 extern char    *forkname[];
-u_char         header_buf[ AD_HEADER_LEN ];
+static u_char  header_buf[ AD_HEADER_LEN ];
 
 /* 
  * single_open must be called first.  pass it a filename that is supposed
@@ -62,10 +58,7 @@ u_char               header_buf[ AD_HEADER_LEN ];
  * somewhat initialized; single_filed is set.
  */
 
-int single_open( singlefile, flags, fh, options )
-    char               *singlefile;
-    int                        flags, options _U_;
-    struct FHeader     *fh;
+int single_open(char *singlefile, int flags, struct FHeader *fh, int options _U_)
 {
     int                        rc;
 
@@ -96,8 +89,7 @@ int single_open( singlefile, flags, fh, options )
  * Otherwise, a value of -1 is returned.
  */
 
-int single_close( keepflag )
-    int                        keepflag;
+int single_close( int keepflag)
 {
     if ( keepflag == KEEP ) {
        return( close( single.filed ));
@@ -116,15 +108,13 @@ int single_close( keepflag )
  * bytes of the other two forks can be read, as well.
  */
 
-int single_header_read( fh, version )
-    struct FHeader     *fh;
-    int                        version;
+int single_header_read( struct FHeader *fh, int version)
 {
 /*
  * entry_buf is used for reading in entry descriptors, and for reading in
  *     the actual entries of FILEINFO, FINDERINFO, and DATES.
  */
-    u_char             entry_buf[ 16 ];
+    u_char             entry_buf[ADEDLEN_FINDERI];
     u_int32_t          entry_id;
     u_int32_t          time_seconds;
     u_short            mask = 0xfcee;
@@ -210,15 +200,14 @@ int single_header_read( fh, version )
            return( -1 );
        }
     }
-    if (( single.entry[ ADEID_FINDERI ].ade_len < 16 ) ||
+    if (( single.entry[ ADEID_FINDERI ].ade_len < ADEDLEN_FINDERI ) ||
            ( single.entry[ ADEID_FINDERI ].ade_off <= AD_HEADER_LEN )) {
        fprintf( stderr, "%s has bogus FinderInfo.\n", single.path );
        return( -1 );
     } else {
        pos = lseek( single.filed,
                single.entry[ ADEID_FINDERI ].ade_off, SEEK_SET );
-       if ( read( single.filed, (char *)entry_buf, sizeof( entry_buf )) !=
-               sizeof( entry_buf )) {
+       if ( read( single.filed, (char *)entry_buf, ADEDLEN_FINDERI) != ADEDLEN_FINDERI) {
            perror( "Premature end of file :" );
            return( -1 );
        }
@@ -310,9 +299,9 @@ int single_header_read( fh, version )
                sizeof(fh->backup_date));
     }
     if ( single.entry[ ADEID_RFORK ].ade_off == 0 ) {
-       fh->forklen[ ADEID_RFORK ] = 0;
+       fh->forklen[RESOURCE] = 0;
     } else {
-       fh->forklen[ ADEID_RFORK ] =
+       fh->forklen[RESOURCE] =
                htonl( single.entry[ ADEID_RFORK ].ade_len );
     }
     if ( single.entry[ ADEID_DFORK ].ade_off == 0 ) {
@@ -339,7 +328,7 @@ int single_header_read( fh, version )
  * "Macintosh       " (that is seven blanks of padding).
  */
 #define MACINTOSH      "Macintosh       "
-u_char         sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
+static u_char          sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0 };
 
 int single_header_test(void)
@@ -395,15 +384,12 @@ int single_header_test(void)
  *
  */
 
-int single_read( fork, buffer, length )
-    int                        fork;
-    char               *buffer;
-    u_int32_t          length;
+ssize_t single_read( int fork, char *buffer, size_t length)
 {
     u_int32_t          entry_id;
     char               *buf_ptr;
-    int                        readlen;
-    int                        cc = 1;
+    size_t             readlen;
+    ssize_t            cc = 1;
     off_t              pos;
 
     switch ( fork ) {
@@ -418,9 +404,9 @@ int single_read( fork, buffer, length )
            break;
     }
 
-    if (single.entry[entry_id].ade_len > length) {
-       fprintf(stderr, "single_read: Trying to read past end of fork!, length %d, ade_len == %u\n", length, single.entry[entry_id].ade_len);
-       return single.entry[entry_id].ade_len;
+    if (single.entry[entry_id].ade_len > 0x7FFFFFFF) {
+       fprintf(stderr, "single_read: Trying to read past end of fork!, ade_len == %u\n", single.entry[entry_id].ade_len);
+       return -1;
     }
     if ( single.entry[ entry_id ].ade_len == 0 ) {
        if ( fork == DATA ) {