/*
- * $Id: desktop.c,v 1.22 2003-01-24 07:08:42 didg Exp $
+ * $Id: desktop.c,v 1.23 2003-02-16 12:35:04 didg Exp $
*
* See COPYRIGHT.
*
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
/*
- * $Id: directory.c,v 1.61 2003-01-31 17:47:06 didg Exp $
+ * $Id: directory.c,v 1.62 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
if (ret != NULL) {
break;
}
- if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL) {
+ if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))) {
afp_errno = AFPERR_NOOBJ;
return NULL;
}
/* free everything down. we don't bother to recolor as this is only
* called to free the entire tree */
+void dirfreename(struct dir *dir)
+{
+ if (dir->d_u_name != dir->d_m_name) {
+ free(dir->d_u_name);
+ }
+ free(dir->d_m_name);
+}
+
void dirfree( dir )
struct dir *dir;
{
}
if (dir != SENTINEL) {
- if (dir->d_u_name != dir->d_m_name) {
- free(dir->d_u_name);
- }
- free(dir->d_m_name);
+ dirfreename(dir);
free( dir );
}
}
return err;
}
}
- closedir(dp);
}
if ( movecwd( vol, curdir->d_parent ) < 0 ) {
- return afp_errno;
+ err = afp_errno;
+ goto delete_done;
}
- if ( (err = netatalk_rmdir(fdir->d_u_name))) {
- return err;
- }
-
- dirchildremove(curdir, fdir);
+ if ( !(err = netatalk_rmdir(fdir->d_u_name))) {
+ dirchildremove(curdir, fdir);
#ifdef CNID_DB
- cnid_delete(vol->v_db, fdir->d_did);
+ cnid_delete(vol->v_db, fdir->d_did);
#endif /* CNID_DB */
- dir_remove( vol, fdir );
-
- return( AFP_OK );
+ dir_remove( vol, fdir );
+ err = AFP_OK;
+ }
+delete_done:
+ if (dp) {
+ /* inode is used as key for cnid.
+ * Close the descriptor only after cnid_delete
+ * has been called.
+ */
+ closedir(dp);
+ }
+ return err;
}
int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
/*
- * $Id: enumerate.c,v 1.33 2003-01-24 07:08:42 didg Exp $
+ * $Id: enumerate.c,v 1.34 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
/* Fail out if things go bad with CNID. */
if (cdir->d_did == CNID_INVALID) {
switch (errno) {
+ case CNID_ERR_CLOSE: /* the db is closed */
+ break;
case CNID_ERR_PARAM:
LOG(log_error, logtype_afpd, "adddir: Incorrect parameters passed to cnid_add");
return NULL;
- it's an ID reused as above
- it's a hash duplicate and we are in big trouble
*/
+ dirfreename(edir);
edir->d_m_name = cdir->d_m_name;
edir->d_u_name = cdir->d_u_name;
free(cdir);
else {
s_path.m_name = NULL;
}
- if (( ret = getdirparams(vol, dbitmap, &s_path, dir,
- data + header , &esz )) != AFP_OK ) {
+ if (AFP_OK != ( ret = getdirparams(vol, dbitmap, &s_path, dir,
+ data + header , &esz ))) {
return( ret );
}
continue;
}
s_path.m_name = utompath(vol, s_path.u_name);
- if (( ret = getfilparams(vol, fbitmap, &s_path, curdir,
- data + header , &esz )) != AFP_OK ) {
+ if (AFP_OK != ( ret = getfilparams(vol, fbitmap, &s_path, curdir,
+ data + header , &esz )) ) {
return( ret );
}
}
/*
- * $Id: file.c,v 1.83 2003-02-04 18:26:20 didg Exp $
+ * $Id: file.c,v 1.84 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
/* -------------------------- */
int getmetadata(struct vol *vol,
u_int16_t bitmap,
- char *path, struct dir *dir, struct stat *st,
+ struct path *path, struct dir *dir,
char *buf, int *buflen, struct adouble *adp, int attrbits )
{
#ifndef USE_LASTDID
u_int16_t ashort;
u_char achar, fdType[4];
u_int32_t utf8 = 0;
-
+ struct stat *st;
#ifdef DEBUG
LOG(log_info, logtype_afpd, "begin getmetadata:");
#endif /* DEBUG */
- upath = mtoupath(vol, path);
+ upath = path->u_name;
+ st = &path->st;
data = buf;
while ( bitmap != 0 ) {
break;
case FILPBIT_FINFO :
- get_finderinfo(path, adp, (char *)data);
+ get_finderinfo(path->m_name, adp, (char *)data);
if (!adp) {
if (*upath == '.') { /* make it invisible */
ashort = htons(FINDERINFO_INVISIBLE);
if ( l_nameoff ) {
ashort = htons( data - buf );
memcpy(l_nameoff, &ashort, sizeof( ashort ));
- data = set_name(data, path, 0);
+ data = set_name(data, path->m_name, 0);
}
if ( utf_nameoff ) {
ashort = htons( data - buf );
memcpy(utf_nameoff, &ashort, sizeof( ashort ));
- data = set_name(data, path, utf8);
+ data = set_name(data, path->m_name, utf8);
}
*buflen = data - buf;
return (AFP_OK);
}
}
}
- rc = getmetadata(vol, bitmap, path->m_name, dir, &path->st, buf, buflen, adp, attrbits);
+ rc = getmetadata(vol, bitmap, path, dir, buf, buflen, adp, attrbits);
if ( adp ) {
ad_close( adp, ADFLAGS_HF );
}
char *ibuf, *rbuf;
int ibuflen, *rbuflen;
{
- struct stat *st;
struct adouble ad, *adp;
struct vol *vol;
struct dir *dir;
openf = O_RDWR|O_CREAT|O_EXCL;
}
- if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF,
+ if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF,
openf, 0666, adp) < 0 ) {
switch ( errno ) {
case EEXIST :
return( AFPERR_EXIST );
case EACCES :
return( AFPERR_ACCESS );
- case ENOENT:
- /* on noadouble volumes, just creating the data fork is ok */
- st = &s_path->st;
- if (vol_noadouble(vol) && (stat(upath, st) == 0))
- goto createfile_done;
- /* fallthrough */
default :
return( AFPERR_PARAM );
}
}
+ if ( ad_hfileno( adp ) == -1 ) {
+ /* on noadouble volumes, just creating the data fork is ok */
+ if (vol_noadouble(vol))
+ goto createfile_done;
+ /* FIXME with hard create on an existing file, we already
+ * corrupted the data file.
+ */
+ netatalk_unlink( upath );
+ ad_close( adp, ADFLAGS_DF );
+ return AFPERR_ACCESS;
+ }
+
path = s_path->m_name;
ad_setentrylen( adp, ADEID_NAME, strlen( path ));
memcpy(ad_entry( adp, ADEID_NAME ), path,
/* FIXME warning in syslog so admin'd know there's a conflict ?*/
return AFPERR_OLOCK; /* little lie */
}
- if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) {
- deletefile( dst, 0 );
+ if (AFP_OK != ( rc = copyfile(src, dst, newname, noadouble )) ) {
+ /* on error copyfile delete dest */
return( rc );
}
- return deletefile( src, 0);
+ return deletefile(NULL, src, 0);
default :
return( AFPERR_PARAM );
}
return AFP_OK;
}
-/* XXX: this needs to use ad_open and ad_lock. so, we need to
- * pass in vol and path */
+/* -------------------------- */
+static int copy_fd(int dfd, int sfd)
+{
+ ssize_t cc;
+ int err = AFP_OK;
+ char filebuf[8192];
+
+#ifdef SENDFILE_FLAVOR_LINUX
+ struct stat st;
+
+ if (fstat(sfd, &st) == 0) {
+ if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
+ switch (errno) {
+ case EINVAL: /* there's no guarantee that all fs support sendfile */
+ break;
+ case EDQUOT:
+ case EFBIG:
+ case ENOSPC:
+ return AFPERR_DFULL;
+ case EROFS:
+ return AFPERR_VLOCK;
+ default:
+ return AFPERR_PARAM;
+ }
+ }
+ else {
+ return AFP_OK;
+ }
+ }
+#endif /* SENDFILE_FLAVOR_LINUX */
+
+ while (1) {
+ if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) {
+ if (errno == EINTR)
+ continue;
+ err = AFPERR_PARAM;
+ break;
+ }
+
+ if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0))
+ break;
+ }
+ return err;
+}
+
+/* ----------------------------------
+ * if newname is NULL (from directory.c) we don't want to copy ressource fork.
+ * because we are doing it elsewhere.
+ */
int copyfile(src, dst, newname, noadouble )
char *src, *dst, *newname;
const int noadouble;
{
- struct adouble ad;
-#ifdef SENDFILE_FLAVOR_LINUX
- struct stat st;
-#endif
- char filebuf[8192];
- int sfd, dfd, len, err = AFP_OK;
- ssize_t cc;
- char dpath[ MAXPATHLEN + 1];
- int admode;
+ struct adouble ads, add;
+ int len, err = AFP_OK;
+ int adflags;
+
#ifdef DEBUG
LOG(log_info, logtype_afpd, "begin copyfile:");
#endif /* DEBUG */
- strcpy(dpath, ad_path( dst, ADFLAGS_HF ));
- admode = ad_mode( dst, 0666 );
+ memset(&ads, 0, sizeof(ads));
+ memset(&add, 0, sizeof(add));
+ adflags = ADFLAGS_DF;
if (newname) {
- if ((sfd = open( ad_path( src, ADFLAGS_HF ), O_RDONLY, 0 )) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- break; /* just copy the data fork */
- case EACCES :
- return( AFPERR_ACCESS );
- default :
- return( AFPERR_PARAM );
- }
- } else {
- if (( dfd = open( dpath, O_WRONLY|O_CREAT,ad_hf_mode(admode))) < 0 ) {
- close( sfd );
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
- }
- }
-
- /* copy the file */
-#ifdef SENDFILE_FLAVOR_LINUX
- if (fstat(sfd, &st) == 0) {
- if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
- switch (errno) {
- case EDQUOT:
- case EFBIG:
- case ENOSPC:
- err = AFPERR_DFULL;
- break;
- case EROFS:
- err = AFPERR_VLOCK;
- break;
- default:
- err = AFPERR_PARAM;
- }
- }
- goto copyheader_done;
- }
-#endif /* SENDFILE_FLAVOR_LINUX */
- while (1) {
- if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) {
- if (errno == EINTR)
- continue;
- err = AFPERR_PARAM;
- break;
- }
-
- if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0))
- break;
- }
-
-copyheader_done:
- close(sfd);
- close(dfd);
- if (err < 0) {
- unlink(dpath);
- return err;
- }
- }
+ adflags |= ADFLAGS_HF;
}
- /* data fork copying */
- if (( sfd = open( src, O_RDONLY, 0 )) < 0 ) {
+ if (ad_open(src , adflags | ADFLAGS_NOHF, O_RDONLY, 0, &ads) < 0) {
switch ( errno ) {
case ENOENT :
return( AFPERR_NOOBJ );
return( AFPERR_PARAM );
}
}
-
- if (( dfd = open( dst, O_WRONLY|O_CREAT, admode)) < 0 ) {
- close( sfd );
- switch ( errno ) {
+ if (ad_open(dst , adflags | noadouble, O_RDWR|O_CREAT|O_EXCL, 0666, &add) < 0) {
+ ad_close( &ads, adflags );
+ if (EEXIST != (err = errno)) {
+ deletefile(NULL, dst, 0);
+ }
+ switch ( err ) {
+ case EEXIST :
+ return AFPERR_EXIST;
case ENOENT :
return( AFPERR_NOOBJ );
case EACCES :
return( AFPERR_PARAM );
}
}
-
-#ifdef SENDFILE_FLAVOR_LINUX
- if (fstat(sfd, &st) == 0) {
- if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
- switch (errno) {
- case EDQUOT:
- case EFBIG:
- case ENOSPC:
- err = AFPERR_DFULL;
- break;
- default:
- err = AFPERR_PARAM;
- }
- }
- goto copydata_done;
+ if (ad_hfileno(&ads) == -1 || AFP_OK == (err = copy_fd(ad_hfileno(&add), ad_hfileno(&ads)))){
+ /* copy the data fork */
+ err = copy_fd(ad_dfileno(&add), ad_dfileno(&ads));
}
-#endif /* SENDFILE_FLAVOR_LINUX */
-
- while (1) {
- if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) {
- if (errno == EINTR)
- continue;
- err = AFPERR_PARAM;
- break;
- }
-
- if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) {
- break;
- }
+ if (newname) {
+ len = strlen( newname );
+ ad_setentrylen( &add, ADEID_NAME, len );
+ memcpy(ad_entry( &add, ADEID_NAME ), newname, len );
}
-copydata_done:
- close(sfd);
- close(dfd);
- if (err < 0) {
- unlink(dpath);
- unlink(dst);
- return err;
+ ad_close( &ads, adflags );
+ ad_flush( &add, adflags );
+ if (ad_close( &add, adflags ) <0) {
+ err = errno;
}
-
- if (newname) {
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( dst, noadouble | ADFLAGS_HF, O_RDWR|O_CREAT,
- 0666, &ad) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- return noadouble ? AFP_OK : AFPERR_NOOBJ;
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
- }
+ if (err != AFP_OK) {
+ deletefile(NULL, dst, 0);
+ switch ( err ) {
+ case ENOENT :
+ return( AFPERR_NOOBJ );
+ case EACCES :
+ return( AFPERR_ACCESS );
+ default :
+ return( AFPERR_PARAM );
}
-
- len = strlen( newname );
- ad_setentrylen( &ad, ADEID_NAME, len );
- memcpy(ad_entry( &ad, ADEID_NAME ), newname, len );
- ad_flush( &ad, ADFLAGS_HF );
- ad_close( &ad, ADFLAGS_HF );
}
#ifdef DEBUG
/* -----------------------------------
- checkAttrib: 1 check kFPDeleteInhibitBit
- ie deletfile called by afp_delete
+ vol: not NULL delete cnid entry. then we are in curdir and file is a only filename
+ checkAttrib: 1 check kFPDeleteInhibitBit (deletfile called by afp_delete)
when deletefile is called we don't have lock on it, file is closed (for us)
untrue if called by renamefile
ad_open always try to open file RDWR first and ad_lock takes care of
WRITE lock on read only file.
*/
-int deletefile( file, checkAttrib )
+int deletefile( vol, file, checkAttrib )
+struct vol *vol;
char *file;
int checkAttrib;
{
if (ad_tmplock( &ad, ADEID_DFORK, ADLOCK_WR, 0, 0, 0 ) < 0) {
err = AFPERR_BUSY;
}
- else if ( 0 == (err = netatalk_unlink( ad_path( file, ADFLAGS_HF )) )) {
- err = netatalk_unlink( file );
+ else if (!(err = netatalk_unlink( ad_path( file, ADFLAGS_HF)) ) &&
+ !(err = netatalk_unlink( file )) ) {
+#ifdef CNID_DB /* get rid of entry */
+ cnid_t id;
+ if (vol && (id = cnid_get(vol->v_db, curdir->d_did, file, strlen(file))))
+ {
+ cnid_delete(vol->v_db, id);
+ }
+#endif /* CNID_DB */
+
}
ad_close( &ad, adflags ); /* ad_close removes locks if any */
return( AFPERR_PARAM );
}
- if (( s_path = cname( vol, dir, &ibuf )) == NULL ) {
+ if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
return afp_errno; /* was AFPERR_PARAM */
}
return AFPERR_NOID; /* was AFPERR_BADID, but help older Macs */
}
- if (( dir = dirlookup( vol, id )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, id )) ) {
return AFPERR_NOID; /* idem AFPERR_PARAM */
}
path.u_name = upath;
memcpy(&bitmap, ibuf, sizeof(bitmap));
bitmap = ntohs( bitmap );
path.m_name = utompath(vol, upath);
- if ((err = getfilparams(vol, bitmap, &path , curdir,
- rbuf + sizeof(bitmap), &buflen)) != AFP_OK) {
+ if (AFP_OK != (err = getfilparams(vol, bitmap, &path , curdir,
+ rbuf + sizeof(bitmap), &buflen))) {
return err;
}
*rbuflen = buflen + sizeof(bitmap);
return AFPERR_NOID;
}
- if (( dir = dirlookup( vol, id )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, id )) ) {
return( AFPERR_PARAM );
}
return AFPERR_PARAM;
}
}
-
- /* directories are bad */
- if (S_ISDIR(st.st_mode))
+ else if (S_ISDIR(st.st_mode)) /* directories are bad */
return AFPERR_BADTYPE;
if (cnid_delete(vol->v_db, fileid)) {
/*
- * $Id: file.h,v 1.14 2002-10-13 06:18:13 didg Exp $
+ * $Id: file.h,v 1.15 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
extern int setfilparams __P((struct vol *, struct path *, u_int16_t, char *));
extern int renamefile __P((char *, char *, char *, const int, struct adouble *));
extern int copyfile __P((char *, char *, char *, const int));
-extern int deletefile __P((char *, int));
+extern int deletefile __P((struct vol *, char *, int));
extern void *get_finderinfo __P((const char *, struct adouble *, void *));
extern int copy_path_name __P((char *, char *i));
/*
- * $Id: filedir.c,v 1.40 2003-01-24 07:08:43 didg Exp $
+ * $Id: filedir.c,v 1.41 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
/* this is a directory */
*(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
} else {
- if (fbitmap && ( ret = getfilparams(vol, fbitmap, s_path, curdir,
- rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
+ if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir,
+ rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
return( ret );
}
/* this is a file */
memcpy( &did, ibuf, sizeof( did));
ibuf += sizeof( did);
- if (( dir = dirlookup( vol, did )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, did )) ) {
return afp_errno;
}
bitmap = ntohs( bitmap );
ibuf += sizeof( bitmap );
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ if (NULL == ( path = cname( vol, dir, &ibuf ))) {
return afp_errno;
}
}
/* source pathname */
- if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
+ if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
return afp_errno;
}
}
} else if (of_findname(s_path)) {
rc = AFPERR_BUSY;
- } else if (AFP_OK == (rc = deletefile( upath, 1))) {
-#ifdef CNID_DB /* get rid of entry */
- cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
- cnid_delete(vol->v_db, id);
-#endif /* CNID_DB */
+ } else {
+ rc = deletefile(vol, upath, 1);
}
if ( rc == AFP_OK ) {
curdir->offcnt--;
/*
- * $Id: fork.c,v 1.48 2003-01-31 17:38:01 didg Exp $
+ * $Id: fork.c,v 1.49 2003-02-16 12:35:04 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
struct ofork *writtenfork;
extern int getmetadata(struct vol *vol,
u_int16_t bitmap,
- char *path, struct dir *dir, struct stat *st,
- char *buf, int *buflen, struct adouble *adp, int attrbits );
+ struct path *path, struct dir *dir, char *buf,
+ int *buflen, struct adouble *adp, int attrbits );
static int getforkparams(ofork, bitmap, buf, buflen, attrbits )
struct ofork *ofork;
int *buflen;
const u_int16_t attrbits;
{
- struct stat st;
- char *upath;
+ struct path path;
+ struct stat *st;
struct adouble *adp;
struct dir *dir;
vol = ofork->of_vol;
dir = ofork->of_dir;
+ path.u_name = mtoupath(vol, ofork->of_name);
+ path.m_name = ofork->of_name;
+ st = &path.st;
if ( bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) |
(1<<FILPBIT_FNUM) | (1 << FILPBIT_CDATE) |
(1 << FILPBIT_MDATE) | (1 << FILPBIT_BDATE))) {
if ( ad_dfileno( ofork->of_ad ) == -1 ) {
- upath = mtoupath(vol, ofork->of_name);
if (movecwd(vol, dir) < 0)
return( AFPERR_NOOBJ );
- if ( stat( upath, &st ) < 0 )
+ if ( stat( path.u_name, st ) < 0 )
return( AFPERR_NOOBJ );
} else {
- if ( fstat( ad_dfileno( ofork->of_ad ), &st ) < 0 ) {
+ if ( fstat( ad_dfileno( ofork->of_ad ), st ) < 0 ) {
return( AFPERR_BITMAP );
}
}
}
- return getmetadata(vol, bitmap, ofork->of_name, dir, &st, buf, buflen, adp, attrbits );
+ return getmetadata(vol, bitmap, &path, dir, buf, buflen, adp, attrbits );
}
/* ---------------------------- */
/* -------------------------
*/
-extern int ad_testlock(struct adouble *adp, int eid, int off);
-
static int getforkmode(struct adouble *adp, int eid, int what)
{
return ad_testlock(adp, eid, what);
* fork if the user wants to open it for write acess. */
if (ad_open(upath, adflags, O_RDWR | O_CREAT, 0666, ofork->of_ad) < 0)
goto openfork_err;
+ ofork->of_flags |= AFPFORK_OPEN;
}
break;
case EMFILE :
break;
}
}
- /* the fork is open */
- ofork->of_flags |= AFPFORK_OPEN;
+ else {
+ /* the ressource fork is open too */
+ ofork->of_flags |= AFPFORK_OPEN;
+ }
} else {
/* try opening in read-only mode */
ret = AFPERR_NOOBJ;
goto openfork_err;
}
adflags = ADFLAGS_DF;
- ofork->of_flags |= AFPFORK_OPEN;
}
/* else we don't set AFPFORK_OPEN because there's no ressource fork file
* We need to check AFPFORK_OPEN in afp_closefork(). eg fork open read-only
}
}
else {
- /* the fork is open */
+ /* the ressource fork is open too */
ofork->of_flags |= AFPFORK_OPEN;
}
}
break;
default:
*rbuflen = 0;
- LOG(log_error, logtype_afpd, "afp_openfork: ad_lock: %s", strerror(errno) );
+ LOG(log_error, logtype_afpd, "afp_openfork: ad_lock: %s", strerror(ret) );
return( AFPERR_PARAM );
}
}
if ( ad_hfileno( of->of_ad ) == -1 ||
memcmp( ufinderi, ad_entry( of->of_ad, ADEID_FINDERI ),
8) == 0 ) {
- if (( em = getextmap( of->of_name )) == NULL ||
+ if (NULL == ( em = getextmap( of->of_name )) ||
memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) {
return( 1 );
} else {
}
adflags = 0;
- if ((ofork->of_flags & AFPFORK_OPEN)) {
- if ((ofork->of_flags & AFPFORK_DATA) && (ad_dfileno( ofork->of_ad ) != -1)) {
+ if ((ofork->of_flags & AFPFORK_DATA) && (ad_dfileno( ofork->of_ad ) != -1)) {
adflags |= ADFLAGS_DF;
- }
- if ( ad_hfileno( ofork->of_ad ) != -1 ) {
- adflags |= ADFLAGS_HF;
- /*
- * Only set the rfork's length if we're closing the rfork.
- */
- if ((ofork->of_flags & AFPFORK_RSRC)) {
- ad_refresh( ofork->of_ad );
- if ((ofork->of_flags & AFPFORK_DIRTY) && !gettimeofday(&tv, NULL)) {
- ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,tv.tv_sec);
- doflush++;
- }
- if ( doflush ) {
- ad_flush( ofork->of_ad, adflags );
- }
+ }
+ if ( (ofork->of_flags & AFPFORK_OPEN) && ad_hfileno( ofork->of_ad ) != -1 ) {
+ adflags |= ADFLAGS_HF;
+ /*
+ * Only set the rfork's length if we're closing the rfork.
+ */
+ if ((ofork->of_flags & AFPFORK_RSRC)) {
+ ad_refresh( ofork->of_ad );
+ if ((ofork->of_flags & AFPFORK_DIRTY) && !gettimeofday(&tv, NULL)) {
+ ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,tv.tv_sec);
+ doflush++;
+ }
+ if ( doflush ) {
+ ad_flush( ofork->of_ad, adflags );
}
}
+ }
- if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
- LOG(log_error, logtype_afpd, "afp_closefork: ad_close: %s", strerror(errno) );
- return( AFPERR_PARAM );
- }
+ if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
+ LOG(log_error, logtype_afpd, "afp_closefork: ad_close: %s", strerror(errno) );
+ return( AFPERR_PARAM );
}
of_dealloc( ofork );
/*
- * $Id: adouble.h,v 1.19 2003-01-31 17:38:02 didg Exp $
+ * $Id: adouble.h,v 1.20 2003-02-16 12:35:05 didg Exp $
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
*
#define ADFLAGS_DIR (1<<2)
#define ADFLAGS_NOADOUBLE (1<<3)
#define ADFLAGS_V1COMPAT (1<<4)
+#define ADFLAGS_NOHF (1<<5) /* not an error if no ressource fork */
/* lock flags */
#define ADLOCK_CLR (0)
const int /*type*/, const off_t /*offset*/,
const off_t /*len*/, const int /*user*/));
+extern int ad_testlock __P((struct adouble * /*adp*/, int /*eid*/, off_t /*off*/));
extern int ad_excl_lock __P((struct adouble * /*adp*/, const u_int32_t /*eid*/));
#define ad_lock ad_fcntl_lock
#define CNID_ERR_PARAM 0x80000001
#define CNID_ERR_PATH 0x80000002
#define CNID_ERR_DB 0x80000003
-#define CNID_ERR_MAX 0x80000004
+#define CNID_ERR_CLOSE 0x80000004 /* the db was not open */
+#define CNID_ERR_MAX 0x80000005
typedef u_int32_t cnid_t;
extern int cnid_mangle_add __P((void *, char *, char *));
extern char *cnid_mangle_get __P((void *, char *));
+extern int cnid_lock __P((void *));
+extern int cnid_unlock __P((void *));
+
#endif /* include/atalk/cnid.h */
/*
- * $Id: ad_lock.c,v 1.10 2003-01-31 11:26:36 didg Exp $
+ * $Id: ad_lock.c,v 1.11 2003-02-16 12:35:05 didg Exp $
*
* Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT for more information.
}
/* ----------------------- */
-
static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen)
{
return (!alen && a <= b) ||
( (a + alen > b) && (b + blen > a) );
}
-
/* allocation for lock regions. we allocate aggressively and shrink
* only in large chunks. */
#define ARRAY_BLOCK_SIZE 10
translate a data fork lock to an offset
*/
-static int df2off(int off)
+static off_t df2off(int off)
{
int start = off;
if (off == AD_FILELOCK_OPEN_WR)
translate a resource fork lock to an offset
*/
-static int hf2off(int off)
+static off_t hf2off(int off)
{
int start = off;
if (off == AD_FILELOCK_OPEN_WR)
{
struct flock lock;
struct ad_fd *adf;
- adf_lock_t *adflock, *oldlock;
+ adf_lock_t *adflock;
+ int oldlock;
int i;
int type;
}
/* it wasn't an upgrade */
- oldlock = NULL;
- if ((lock.l_type == F_RDLCK) &&
- ((i = adf_findxlock(adf, user, ADLOCK_RD, lock.l_start, lock.l_len)) > -1)) {
- oldlock = adf->adf_lock + i;
+ oldlock = -1;
+ if (lock.l_type == F_RDLCK) {
+ oldlock = adf_findxlock(adf, user, ADLOCK_RD, lock.l_start, lock.l_len);
}
/* no more space. this will also happen if lockmax == lockcount == 0 */
/* fill in fields */
memcpy(&adflock->lock, &lock, sizeof(lock));
adflock->user = user;
- if (oldlock)
- adflock->refcount = oldlock->refcount;
- else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
+ if (oldlock > -1) {
+ adflock->refcount = (adf->adf_lock + oldlock)->refcount;
+ } else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
goto fcntl_lock_err;
}
/*
- * $Id: ad_open.c,v 1.26 2003-01-24 06:58:25 didg Exp $
+ * $Id: ad_open.c,v 1.27 2003-02-16 12:35:05 didg Exp $
*
* Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
* Copyright (c) 1990,1991 Regents of The University of Michigan.
return ret;
}
+/* ----------------- */
+static int ad_error(struct adouble *ad, int adflags)
+{
+ if ((adflags & ADFLAGS_NOHF)) {
+ /* FIXME double check : set header offset ?*/
+ return 0;
+ }
+ if ((adflags & ADFLAGS_DF)) {
+ ad_close( ad, ADFLAGS_DF );
+ }
+ return -1 ;
+}
static int new_rfork(const char *path, struct adouble *ad, int adflags);
*/
if (errno == ENOENT && (adflags & ADFLAGS_NOADOUBLE) == 0) {
if (NULL == ( slash = strrchr( ad_p, '/' )) ) {
- ad_close( ad, open_df );
- return( -1 );
+ return ad_error(ad, adflags);
}
*slash = '\0';
errno = 0;
if ( ad_mkdir( ad_p, 0777 ) < 0 ) {
- ad_close( ad, adflags );
- return( -1 );
+ return ad_error(ad, adflags);
}
*slash = '/';
admode = mode;
admode = ad_hf_mode(admode);
ad->ad_hf.adf_fd = open( ad_p, oflags, admode);
if ( ad->ad_hf.adf_fd < 0 ) {
- ad_close( ad, open_df );
- return( -1 );
+ return ad_error(ad, adflags);
}
} else {
- ad_close( ad, open_df );
- return( -1 );
+ return ad_error(ad, adflags);
}
}
ad->ad_hf.adf_flags = oflags;
if (!st_invalid) {
ad_chown(path, &st);
}
- } else {
- ad_close( ad, open_df );
- return( -1 );
+ }
+ else {
+ return ad_error(ad, adflags);
}
} else if (fstat(ad->ad_hf.adf_fd, &st) == 0 && st.st_size == 0) {
/* for 0 length files, treat them as new. */
* instead of reading it.
*/
if (new_rfork(path, ad, adflags) < 0) {
+ /* the file is already deleted, perm, whatever, so return an error*/
ad_close(ad, adflags);
return -1;
}