[comp.protocols.appletalk] CAP/AUFS bug & patch

djh@cs.mu.oz.au (David Hornsby) (12/11/90)

priority: low/medium
affects: all CAP 5.0 & derived distributions

The AFP command FPCreateFile contains a flag to specify
a hard or soft create (soft create returns ObjectExists
if a file by that name already exists).

AUFS never detects a hard create attempt due to an incorrect bit mask.
Fortunately (or otherwise) the Mac AppleShare client software ignores
the returned error and works around it by rewriting the file forks.

AppleShare PC, however, performs differently and a write or copy over
an existing file fails with an error.

The following patches should be applied to the files netat/afpcmd.h and
applications/aufs/afpfile.c (the latter is a fix for a debug print only).
Your line numbers will probably vary ...

--------------------cut-x-here----------------------
*** afpcmd.h.orig	Tue Dec 11 18:12:21 1990
--- afpcmd.h		Tue Dec 11 03:42:15 1990
***************
*** 118,124 ****
  typedef struct {		/* FPCreateFile */
    byte crf_cmd;			/* command */
    byte crf_flg;			/* flags */
! #define CRF_HARD 0x01		/*  hard create */
    word crf_volid;		/* volume id */
    sdword crf_dirid;		/* directory id */
    byte crf_ptype;		/* path name type */
--- 120,126 ----
  typedef struct {		/* FPCreateFile */
    byte crf_cmd;			/* command */
    byte crf_flg;			/* flags */
! #define CRF_HARD 0x80		/* hard create */
    word crf_volid;		/* volume id */
    sdword crf_dirid;		/* directory id */
    byte crf_ptype;		/* path name type */
  
--------------------cut-x-here----------------------
*** afpfile.c.orig	Tue Dec 11 18:22:12 1990
--- afpfile.c		Tue Dec 11 03:31:59 1990
***************
*** 104,111 ****
    delf = (crf.crf_flg & CRF_HARD) != 0;
  
    if (DBFIL) 
!     printf("FPCreateFile flg=%s, path=%s, fn=%s\n",
! 	   crf.crf_flg,pathstr(ipdir),file);
  
    err = OSCreateFile(ipdir,file,delf);
    if (err == noErr)			/* if success */
--- 106,113 ----
    delf = (crf.crf_flg & CRF_HARD) != 0;
  
    if (DBFIL) 
!     printf("FPCreateFile flg=%02x, delf=%d, path=%s, fn=%s\n",
! 	   crf.crf_flg,delf,pathstr(ipdir),file);
  
    err = OSCreateFile(ipdir,file,delf);
    if (err == noErr)			/* if success */

--------------------cut-x-here----------------------

- David

David Hornsby
Professional Officer					djh@munnari.OZ.AU
Department of Computer Science "The home of Multigate"	+61 3 344 4044
The University of Melbourne, Parkville, 3052, Victoria, Australia.

djh@cs.mu.oz.au (David Hornsby) (12/16/90)

Fix one bug and another shows up :-(

Priority: medium/high
Affects: CAP5.0 and derivatives.

Symptom: Existing files 'created' with FPCreateFile (hard create flag)
were not being truncated to zero length before writing. This only became
obvious after the previous FPCreatFile bug fix was applied.

Fix: add truncate flag to the open() in applications/aufs/afpos.c in the
routines unix_create() and unix_createo(). There are TWO lines of the form

  flg = (delf) ? O_CREAT : O_CREAT | O_EXCL;
  
which become ...

  flg = (delf) ? O_CREAT | O_TRUNC : O_CREAT | O_EXCL;
  
Thanks to Ed Moy for pointing out this behaviour. If you are running on a
host that doesn't understand O_TRUNC, please email me and I will make a
more portable fix for this problem.

 - David.

David Hornsby						...!uunet!munnari!djh
Professional Officer					djh@munnari.OZ.AU
Department of Computer Science "The home of Multigate"	+61 3 344 4044
The University of Melbourne, Parkville, 3052, Victoria, Australia.