/*
- * $Id: enumerate.c,v 1.13 2002-01-04 04:45:47 sibaz Exp $
+ * $Id: enumerate.c,v 1.14 2002-01-17 16:19:07 jmarcus Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
/* add to cnid db */
cdir->d_did = cnid_add(vol->v_db, st, dir->d_did, upath,
upathlen, cdir->d_did);
+ /* Fail out if things go bad with CNID. */
+ if (cdir->d_did > CNID_MAX) {
+ switch (cdir->d_did) {
+ case CNID_ERR_PARAM:
+ LOG(log_error, logtype_default, "adddir: Incorrect parameters passed to cnid_add");
+ return NULL;
+ case CNID_ERR_PATH:
+ case CNID_ERR_DB:
+ case CNID_ERR_MAX:
+ return NULL;
+ }
+ }
#endif /* CNID_DB */
if (cdir->d_did == 0) {
if ((buf = (char *) realloc( sd.sd_buf, sd.sd_buflen +
SDBUFBRK )) == NULL ) {
LOG(log_error, logtype_default, "afp_enumerate: realloc: %s",
- strerror(errno) );
+ strerror(errno) );
closedir(dp);
*rbuflen = 0;
return AFPERR_MISC;
if ( stat( sd.sd_last, &st ) < 0 ) {
LOG(log_debug, logtype_default, "afp_enumerate: stat %s: %s",
- sd.sd_last, strerror(errno) );
+ sd.sd_last, strerror(errno) );
sd.sd_last += len + 1;
continue;
}
/*
- * $Id: file.c,v 1.35 2002-01-04 04:45:47 sibaz Exp $
+ * $Id: file.c,v 1.36 2002-01-17 16:19:06 jmarcus Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#ifdef CNID_DB
aint = cnid_add(vol->v_db, st, dir->d_did, upath,
strlen(upath), aint);
+ /* Throw errors if cnid_add fails. */
+ if (aint > CNID_MAX) {
+ switch (aint) {
+ case CNID_ERR_PARAM:
+ LOG(log_error, logtype_default, "getfilparams: Incorrect parameters passed to cnid_add");
+ return(AFPERR_PARAM);
+ case CNID_ERR_PATH:
+ return(AFPERR_PARAM);
+ case CNID_ERR_DB:
+ case CNID_ERR_MAX:
+ return(AFPERR_MISC);
+ }
#endif /* CNID_DB */
- if (aint == 0) {
- /*
- * What a fucking mess. First thing: DID and FNUMs are
- * in the same space for purposes of enumerate (and several
- * other wierd places). While we consider this Apple's bug,
- * this is the work-around: In order to maintain constant and
- * unique DIDs and FNUMs, we monotonically generate the DIDs
- * during the session, and derive the FNUMs from the filesystem.
- * Since the DIDs are small, we insure that the FNUMs are fairly
- * large by setting thier high bits to the device number.
- *
- * AFS already does something very similar to this for the
- * inode number, so we don't repeat the procedure.
- *
- * new algorithm:
- * due to complaints over did's being non-persistent,
- * here's the current hack to provide semi-persistent
- * did's:
- * 1) we reserve the first bit for file ids.
- * 2) the next 7 bits are for the device.
- * 3) the remaining 24 bits are for the inode.
- *
- * both the inode and device information are actually hashes
- * that are then truncated to the requisite bit length.
- *
- * it should be okay to use lstat to deal with symlinks.
- */
+ if (aint == 0) {
+ /*
+ * What a fucking mess. First thing: DID and FNUMs are
+ * in the same space for purposes of enumerate (and several
+ * other wierd places). While we consider this Apple's bug,
+ * this is the work-around: In order to maintain constant and
+ * unique DIDs and FNUMs, we monotonically generate the DIDs
+ * during the session, and derive the FNUMs from the filesystem.
+ * Since the DIDs are small, we insure that the FNUMs are fairly
+ * large by setting thier high bits to the device number.
+ *
+ * AFS already does something very similar to this for the
+ * inode number, so we don't repeat the procedure.
+ *
+ * new algorithm:
+ * due to complaints over did's being non-persistent,
+ * here's the current hack to provide semi-persistent
+ * did's:
+ * 1) we reserve the first bit for file ids.
+ * 2) the next 7 bits are for the device.
+ * 3) the remaining 24 bits are for the inode.
+ *
+ * both the inode and device information are actually hashes
+ * that are then truncated to the requisite bit length.
+ *
+ * it should be okay to use lstat to deal with symlinks.
+ */
#ifdef USE_LASTDID
- aint = htonl(( st->st_dev << 16 ) | (st->st_ino & 0x0000ffff));
+ aint = htonl(( st->st_dev << 16 ) | (st->st_ino & 0x0000ffff));
#else /* USE_LASTDID */
- lstp = lstat(upath, &lst) < 0 ? st : &lst;
+ lstp = lstat(upath, &lst) < 0 ? st : &lst;
#ifdef DID_MTAB
- aint = htonl( afpd_st_cnid ( lstp ) );
+ aint = htonl( afpd_st_cnid ( lstp ) );
#else /* DID_MTAB */
- aint = htonl(CNID(lstp, 1));
+ aint = htonl(CNID(lstp, 1));
#endif /* DID_MTAB */
#endif /* USE_LASTDID */
- }
-
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
-
- case FILPBIT_DFLEN :
- aint = htonl( st->st_size );
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
+ }
- case FILPBIT_RFLEN :
- if ( isad ) {
- aint = htonl( ad_getentrylen( adp, ADEID_RFORK ));
- } else {
- aint = 0;
- }
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
- /* Current client needs ProDOS info block for this file.
- Use simple heuristic and let the Mac "type" string tell
- us what the PD file code should be. Everything gets a
- subtype of 0x0000 unless the original value was hashed
- to "pXYZ" when we created it. See IA, Ver 2.
- <shirsch@ibm.net> */
- case FILPBIT_PDINFO :
- if ( isad ) {
- memcpy(fdType, ad_entry( adp, ADEID_FINDERI ), 4 );
+ case FILPBIT_DFLEN :
+ aint = htonl( st->st_size );
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
- if ( memcmp( fdType, "TEXT", 4 ) == 0 ) {
- achar = '\x04';
- ashort = 0x0000;
- }
- else if ( memcmp( fdType, "PSYS", 4 ) == 0 ) {
- achar = '\xff';
- ashort = 0x0000;
- }
- else if ( memcmp( fdType, "PS16", 4 ) == 0 ) {
- achar = '\xb3';
- ashort = 0x0000;
- }
- else if ( memcmp( fdType, "BINA", 4 ) == 0 ) {
- achar = '\x00';
- ashort = 0x0000;
+ case FILPBIT_RFLEN :
+ if ( isad ) {
+ aint = htonl( ad_getentrylen( adp, ADEID_RFORK ));
+ } else {
+ aint = 0;
}
- else if ( fdType[0] == 'p' ) {
- achar = fdType[1];
- ashort = (fdType[2] * 256) + fdType[3];
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
+
+ /* Current client needs ProDOS info block for this file.
+ Use simple heuristic and let the Mac "type" string tell
+ us what the PD file code should be. Everything gets a
+ subtype of 0x0000 unless the original value was hashed
+ to "pXYZ" when we created it. See IA, Ver 2.
+ <shirsch@ibm.net> */
+ case FILPBIT_PDINFO :
+ if ( isad ) {
+ memcpy(fdType, ad_entry( adp, ADEID_FINDERI ), 4 );
+
+ if ( memcmp( fdType, "TEXT", 4 ) == 0 ) {
+ achar = '\x04';
+ ashort = 0x0000;
+ }
+ else if ( memcmp( fdType, "PSYS", 4 ) == 0 ) {
+ achar = '\xff';
+ ashort = 0x0000;
+ }
+ else if ( memcmp( fdType, "PS16", 4 ) == 0 ) {
+ achar = '\xb3';
+ ashort = 0x0000;
+ }
+ else if ( memcmp( fdType, "BINA", 4 ) == 0 ) {
+ achar = '\x00';
+ ashort = 0x0000;
+ }
+ else if ( fdType[0] == 'p' ) {
+ achar = fdType[1];
+ ashort = (fdType[2] * 256) + fdType[3];
+ }
+ else {
+ achar = '\x00';
+ ashort = 0x0000;
+ }
}
else {
achar = '\x00';
ashort = 0x0000;
}
- }
- else {
- achar = '\x00';
- ashort = 0x0000;
- }
- *data++ = achar;
- *data++ = 0;
- memcpy(data, &ashort, sizeof( ashort ));
- data += sizeof( ashort );
- memset(data, 0, sizeof( ashort ));
- data += sizeof( ashort );
- break;
+ *data++ = achar;
+ *data++ = 0;
+ memcpy(data, &ashort, sizeof( ashort ));
+ data += sizeof( ashort );
+ memset(data, 0, sizeof( ashort ));
+ data += sizeof( ashort );
+ break;
- default :
- if ( isad ) {
- ad_close( adp, ADFLAGS_HF );
+ default :
+ if ( isad ) {
+ ad_close( adp, ADFLAGS_HF );
+ }
+ return( AFPERR_BITMAP );
}
- return( AFPERR_BITMAP );
+ bitmap = bitmap>>1;
+ bit++;
}
- bitmap = bitmap>>1;
- bit++;
- }
- if ( nameoff ) {
- ashort = htons( data - buf );
- memcpy(nameoff, &ashort, sizeof( ashort ));
- if ((aint = strlen( path )) > MACFILELEN)
- aint = MACFILELEN;
- *data++ = aint;
- memcpy(data, path, aint );
- data += aint;
- }
- if ( isad ) {
- ad_close( adp, ADFLAGS_HF );
- }
- *buflen = data - buf;
+ if ( nameoff ) {
+ ashort = htons( data - buf );
+ memcpy(nameoff, &ashort, sizeof( ashort ));
+ if ((aint = strlen( path )) > MACFILELEN)
+ aint = MACFILELEN;
+ *data++ = aint;
+ memcpy(data, path, aint );
+ data += aint;
+ }
+ if ( isad ) {
+ ad_close( adp, ADFLAGS_HF );
+ }
+ *buflen = data - buf;
#ifdef DEBUG
- LOG(log_info, logtype_default, "end getfilparams:");
+ LOG(log_info, logtype_default, "end getfilparams:");
#endif /* DEBUG */
- return( AFP_OK );
-}
-
-int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct stat st;
- struct adouble ad, *adp;
- struct vol *vol;
- struct dir *dir;
- struct ofork *of;
- char *path, *upath;
- int creatf, did, openf, retvalue = AFP_OK;
- u_int16_t vid;
+ return( AFP_OK );
+ }
+
+ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct stat st;
+ struct adouble ad, *adp;
+ struct vol *vol;
+ struct dir *dir;
+ struct ofork *of;
+ char *path, *upath;
+ int creatf, did, openf, retvalue = AFP_OK;
+ u_int16_t vid;
#ifdef FORCE_UIDGID
- uidgidset *uidgid;
+ uidgidset *uidgid;
#endif /* FORCE_UIDGID */
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_createfile:");
+ LOG(log_info, logtype_default, "begin afp_createfile:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf++;
- creatf = (unsigned char) *ibuf++;
+ *rbuflen = 0;
+ ibuf++;
+ creatf = (unsigned char) *ibuf++;
- memcpy(&vid, ibuf, sizeof( vid ));
- ibuf += sizeof( vid );
+ memcpy(&vid, ibuf, sizeof( vid ));
+ ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- memcpy(&did, ibuf, sizeof( did));
- ibuf += sizeof( did );
+ memcpy(&did, ibuf, sizeof( did));
+ ibuf += sizeof( did );
- if (( dir = dirsearch( vol, did )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- if (!wincheck(vol, path))
- return AFPERR_PARAM;
+ if (!wincheck(vol, path))
+ return AFPERR_PARAM;
- upath = mtoupath(vol, path);
+ upath = mtoupath(vol, path);
- if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/'))
- return AFPERR_PARAM;
+ if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/'))
+ return AFPERR_PARAM;
- if (!validupath(vol, upath))
- return AFPERR_EXIST;
+ if (!validupath(vol, upath))
+ return AFPERR_EXIST;
- /* check for vetoed filenames */
- if (veto_file(vol->v_veto, upath))
- return AFPERR_EXIST;
+ /* check for vetoed filenames */
+ if (veto_file(vol->v_veto, upath))
+ return AFPERR_EXIST;
- if ((of = of_findname(vol, curdir, path))) {
- adp = of->of_ad;
- } else {
- memset(&ad, 0, sizeof(ad));
- adp = &ad;
- }
- if ( creatf) {
- /* on a hard create, fail if file exists and is open */
- if ((stat(upath, &st) == 0) && of)
- return AFPERR_BUSY;
- openf = O_RDWR|O_CREAT|O_TRUNC;
- } else {
- openf = O_RDWR|O_CREAT|O_EXCL;
- }
+ if ((of = of_findname(vol, curdir, path))) {
+ adp = of->of_ad;
+ } else {
+ memset(&ad, 0, sizeof(ad));
+ adp = &ad;
+ }
+ if ( creatf) {
+ /* on a hard create, fail if file exists and is open */
+ if ((stat(upath, &st) == 0) && of)
+ return AFPERR_BUSY;
+ openf = O_RDWR|O_CREAT|O_TRUNC;
+ } else {
+ openf = O_RDWR|O_CREAT|O_EXCL;
+ }
#ifdef FORCE_UIDGID
- /* preserve current euid, egid */
- save_uidgid ( uidgid );
+ /* preserve current euid, egid */
+ save_uidgid ( uidgid );
- /* perform all switching of users */
- set_uidgid ( vol );
+ /* perform all switching of users */
+ set_uidgid ( vol );
#endif /* FORCE_UIDGID */
- if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF,
- openf, 0666, adp) < 0 ) {
- switch ( errno ) {
- case EEXIST :
+ if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF,
+ openf, 0666, adp) < 0 ) {
+ switch ( errno ) {
+ case EEXIST :
#ifdef FORCE_UIDGID
- /* bring everything back to old euid, egid */
- restore_uidgid ( uidgid );
+ /* bring everything back to old euid, egid */
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- return( AFPERR_EXIST );
- case EACCES :
+ return( AFPERR_EXIST );
+ case EACCES :
#ifdef FORCE_UIDGID
- /* bring everything back to old euid, egid */
- restore_uidgid ( uidgid );
+ /* bring everything back to old euid, egid */
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- return( AFPERR_ACCESS );
- case ENOENT:
- /* on noadouble volumes, just creating the data fork is ok */
- if (vol_noadouble(vol) && (stat(upath, &st) == 0))
- goto createfile_done;
- /* fallthrough */
- default :
+ return( AFPERR_ACCESS );
+ case ENOENT:
+ /* on noadouble volumes, just creating the data fork is ok */
+ if (vol_noadouble(vol) && (stat(upath, &st) == 0))
+ goto createfile_done;
+ /* fallthrough */
+ default :
#ifdef FORCE_UIDGID
- /* bring everything back to old euid, egid */
- restore_uidgid ( uidgid );
+ /* bring everything back to old euid, egid */
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- return( AFPERR_PARAM );
+ return( AFPERR_PARAM );
+ }
}
- }
- ad_setentrylen( adp, ADEID_NAME, strlen( path ));
- memcpy(ad_entry( adp, ADEID_NAME ), path,
- ad_getentrylen( adp, ADEID_NAME ));
- ad_flush( adp, ADFLAGS_DF|ADFLAGS_HF );
- ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
+ ad_setentrylen( adp, ADEID_NAME, strlen( path ));
+ memcpy(ad_entry( adp, ADEID_NAME ), path,
+ ad_getentrylen( adp, ADEID_NAME ));
+ ad_flush( adp, ADFLAGS_DF|ADFLAGS_HF );
+ ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
createfile_done:
#ifdef DROPKLUDGE
- if (vol->v_flags & AFPVOL_DROPBOX) {
- retvalue = matchfile2dirperms(upath, vol, did);
- }
+ if (vol->v_flags & AFPVOL_DROPBOX) {
+ retvalue = matchfile2dirperms(upath, vol, did);
+ }
#endif /* DROPKLUDGE */
- setvoltime(obj, vol );
+ setvoltime(obj, vol );
#ifdef DEBUG
- LOG(log_info, logtype_default, "end afp_createfile");
+ LOG(log_info, logtype_default, "end afp_createfile");
#endif /* DEBUG */
#ifdef FORCE_UIDGID
- /* bring everything back to old euid, egid */
- restore_uidgid ( uidgid );
+ /* bring everything back to old euid, egid */
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- return (retvalue);
-}
+ return (retvalue);
+ }
-int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct vol *vol;
- struct dir *dir;
- char *path;
- int did, rc;
- u_int16_t vid, bitmap;
+ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct vol *vol;
+ struct dir *dir;
+ char *path;
+ int did, rc;
+ u_int16_t vid, bitmap;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_setfilparams:");
+ LOG(log_info, logtype_default, "begin afp_setfilparams:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&vid, ibuf, sizeof( vid ));
- ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ memcpy(&vid, ibuf, sizeof( vid ));
+ ibuf += sizeof( vid );
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- memcpy(&did, ibuf, sizeof( did ));
- ibuf += sizeof( did );
- if (( dir = dirsearch( vol, did )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ memcpy(&did, ibuf, sizeof( did ));
+ ibuf += sizeof( did );
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- memcpy(&bitmap, ibuf, sizeof( bitmap ));
- bitmap = ntohs( bitmap );
- ibuf += sizeof( bitmap );
+ memcpy(&bitmap, ibuf, sizeof( bitmap ));
+ bitmap = ntohs( bitmap );
+ ibuf += sizeof( bitmap );
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- if ((u_long)ibuf & 1 ) {
- ibuf++;
- }
+ if ((u_long)ibuf & 1 ) {
+ ibuf++;
+ }
- if (( rc = setfilparams(vol, path, bitmap, ibuf )) == AFP_OK ) {
- setvoltime(obj, vol );
- }
+ if (( rc = setfilparams(vol, path, bitmap, ibuf )) == AFP_OK ) {
+ setvoltime(obj, vol );
+ }
#ifdef DEBUG
- LOG(log_info, logtype_default, "end afp_setfilparams:");
+ LOG(log_info, logtype_default, "end afp_setfilparams:");
#endif /* DEBUG */
- return( rc );
-}
+ return( rc );
+ }
-int setfilparams(struct vol *vol,
- char *path, u_int16_t bitmap, char *buf )
-{
- struct adouble ad, *adp;
- struct ofork *of;
- struct extmap *em;
- int bit = 0, isad = 1, err = AFP_OK;
- char *upath;
- u_char achar, *fdType, xyy[4];
- u_int16_t ashort, bshort;
- u_int32_t aint;
- struct utimbuf ut;
+ int setfilparams(struct vol *vol,
+ char *path, u_int16_t bitmap, char *buf )
+ {
+ struct adouble ad, *adp;
+ struct ofork *of;
+ struct extmap *em;
+ int bit = 0, isad = 1, err = AFP_OK;
+ char *upath;
+ u_char achar, *fdType, xyy[4];
+ u_int16_t ashort, bshort;
+ u_int32_t aint;
+ struct utimbuf ut;
#ifdef FORCE_UIDGID
- uidgidset *uidgid;
+ uidgidset *uidgid;
- uidgid = malloc(sizeof(uidgidset));
+ uidgid = malloc(sizeof(uidgidset));
#endif /* FORCE_UIDGID */
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin setfilparams:");
+ LOG(log_info, logtype_default, "begin setfilparams:");
#endif /* DEBUG */
- upath = mtoupath(vol, path);
- if ((of = of_findname(vol, curdir, path))) {
- adp = of->of_ad;
- } else {
- memset(&ad, 0, sizeof(ad));
- adp = &ad;
- }
+ upath = mtoupath(vol, path);
+ if ((of = of_findname(vol, curdir, path))) {
+ adp = of->of_ad;
+ } else {
+ memset(&ad, 0, sizeof(ad));
+ adp = &ad;
+ }
#ifdef FORCE_UIDGID
- save_uidgid ( uidgid );
- set_uidgid ( vol );
+ save_uidgid ( uidgid );
+ set_uidgid ( vol );
#endif /* FORCE_UIDGID */
- if (ad_open( upath, vol_noadouble(vol) | ADFLAGS_HF,
- O_RDWR|O_CREAT, 0666, adp) < 0) {
- /* for some things, we don't need an adouble header */
- if (bitmap & ~(1<<FILPBIT_MDATE)) {
+ if (ad_open( upath, vol_noadouble(vol) | ADFLAGS_HF,
+ O_RDWR|O_CREAT, 0666, adp) < 0) {
+ /* for some things, we don't need an adouble header */
+ if (bitmap & ~(1<<FILPBIT_MDATE)) {
#ifdef FORCE_UIDGID
- restore_uidgid ( uidgid );
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- return vol_noadouble(vol) ? AFP_OK : AFPERR_ACCESS;
- }
- isad = 0;
- } else if ((ad_getoflags( adp, ADFLAGS_HF ) & O_CREAT) ) {
- ad_setentrylen( adp, ADEID_NAME, strlen( path ));
- memcpy(ad_entry( adp, ADEID_NAME ), path,
- ad_getentrylen( adp, ADEID_NAME ));
- }
-
- while ( bitmap != 0 ) {
- while (( bitmap & 1 ) == 0 ) {
- bitmap = bitmap>>1;
- bit++;
+ return vol_noadouble(vol) ? AFP_OK : AFPERR_ACCESS;
+ }
+ isad = 0;
+ } else if ((ad_getoflags( adp, ADFLAGS_HF ) & O_CREAT) ) {
+ ad_setentrylen( adp, ADEID_NAME, strlen( path ));
+ memcpy(ad_entry( adp, ADEID_NAME ), path,
+ ad_getentrylen( adp, ADEID_NAME ));
}
- switch( bit ) {
- case FILPBIT_ATTR :
- memcpy(&ashort, buf, sizeof( ashort ));
- ad_getattr(adp, &bshort);
- if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
- bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
- } else {
- bshort &= ~ashort;
+ while ( bitmap != 0 ) {
+ while (( bitmap & 1 ) == 0 ) {
+ bitmap = bitmap>>1;
+ bit++;
}
- ad_setattr(adp, bshort);
- buf += sizeof( ashort );
- break;
-
- case FILPBIT_CDATE :
- memcpy(&aint, buf, sizeof(aint));
- ad_setdate(adp, AD_DATE_CREATE, aint);
- buf += sizeof( aint );
- break;
-
- case FILPBIT_MDATE :
- memcpy(&aint, buf, sizeof( aint ));
- if (isad)
- ad_setdate(adp, AD_DATE_MODIFY, aint);
- ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint);
- utime(upath, &ut);
- buf += sizeof( aint );
- break;
- case FILPBIT_BDATE :
- memcpy(&aint, buf, sizeof(aint));
- ad_setdate(adp, AD_DATE_BACKUP, aint);
- buf += sizeof( aint );
- break;
-
- case FILPBIT_FINFO :
- if ((memcmp( ad_entry( adp, ADEID_FINDERI ), ufinderi, 8 ) == 0)
- && (em = getextmap( path )) &&
- (memcmp(buf, em->em_type, sizeof( em->em_type )) == 0) &&
- (memcmp(buf + 4, em->em_creator,
- sizeof( em->em_creator )) == 0)) {
- memcpy(buf, ufinderi, 8 );
- }
- memcpy(ad_entry( adp, ADEID_FINDERI ), buf, 32 );
- buf += 32;
- break;
+ switch( bit ) {
+ case FILPBIT_ATTR :
+ memcpy(&ashort, buf, sizeof( ashort ));
+ ad_getattr(adp, &bshort);
+ if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
+ bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
+ } else {
+ bshort &= ~ashort;
+ }
+ ad_setattr(adp, bshort);
+ buf += sizeof( ashort );
+ break;
- /* Client needs to set the ProDOS file info for this file.
- Use defined strings for the simple cases, and convert
- all else into pXYY per Inside Appletalk. Always set
- the creator as "pdos". <shirsch@ibm.net> */
- case FILPBIT_PDINFO :
- achar = *buf;
- buf += 2;
- memcpy(&ashort, buf, sizeof( ashort ));
- ashort = ntohs( ashort );
- buf += 2;
-
- switch ( (unsigned int) achar )
- {
- case 0x04 :
- fdType = ( u_char *) "TEXT";
+ case FILPBIT_CDATE :
+ memcpy(&aint, buf, sizeof(aint));
+ ad_setdate(adp, AD_DATE_CREATE, aint);
+ buf += sizeof( aint );
break;
- case 0xff :
- fdType = ( u_char *) "PSYS";
+ case FILPBIT_MDATE :
+ memcpy(&aint, buf, sizeof( aint ));
+ if (isad)
+ ad_setdate(adp, AD_DATE_MODIFY, aint);
+ ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint);
+ utime(upath, &ut);
+ buf += sizeof( aint );
break;
- case 0xb3 :
- fdType = ( u_char *) "PS16";
+ case FILPBIT_BDATE :
+ memcpy(&aint, buf, sizeof(aint));
+ ad_setdate(adp, AD_DATE_BACKUP, aint);
+ buf += sizeof( aint );
break;
- case 0x00 :
- fdType = ( u_char *) "BINA";
+ case FILPBIT_FINFO :
+ if ((memcmp( ad_entry( adp, ADEID_FINDERI ), ufinderi, 8 ) == 0)
+ && (em = getextmap( path )) &&
+ (memcmp(buf, em->em_type, sizeof( em->em_type )) == 0) &&
+ (memcmp(buf + 4, em->em_creator,
+ sizeof( em->em_creator )) == 0)) {
+ memcpy(buf, ufinderi, 8 );
+ }
+ memcpy(ad_entry( adp, ADEID_FINDERI ), buf, 32 );
+ buf += 32;
break;
- default :
- xyy[0] = ( u_char ) 'p';
- xyy[1] = achar;
- xyy[2] = ( u_char ) ( ashort >> 8 ) & 0xff;
- xyy[3] = ( u_char ) ashort & 0xff;
- fdType = xyy;
+ /* Client needs to set the ProDOS file info for this file.
+ Use defined strings for the simple cases, and convert
+ all else into pXYY per Inside Appletalk. Always set
+ the creator as "pdos". <shirsch@ibm.net> */
+ case FILPBIT_PDINFO :
+ achar = *buf;
+ buf += 2;
+ memcpy(&ashort, buf, sizeof( ashort ));
+ ashort = ntohs( ashort );
+ buf += 2;
+
+ switch ( (unsigned int) achar )
+ {
+ case 0x04 :
+ fdType = ( u_char *) "TEXT";
+ break;
+
+ case 0xff :
+ fdType = ( u_char *) "PSYS";
+ break;
+
+ case 0xb3 :
+ fdType = ( u_char *) "PS16";
+ break;
+
+ case 0x00 :
+ fdType = ( u_char *) "BINA";
+ break;
+
+ default :
+ xyy[0] = ( u_char ) 'p';
+ xyy[1] = achar;
+ xyy[2] = ( u_char ) ( ashort >> 8 ) & 0xff;
+ xyy[3] = ( u_char ) ashort & 0xff;
+ fdType = xyy;
+ break;
+ }
+
+ memcpy(ad_entry( adp, ADEID_FINDERI ), fdType, 4 );
+ memcpy(ad_entry( adp, ADEID_FINDERI ) + 4, "pdos", 4 );
break;
- }
- memcpy(ad_entry( adp, ADEID_FINDERI ), fdType, 4 );
- memcpy(ad_entry( adp, ADEID_FINDERI ) + 4, "pdos", 4 );
- break;
+ default :
+ err = AFPERR_BITMAP;
+ goto setfilparam_done;
+ }
- default :
- err = AFPERR_BITMAP;
- goto setfilparam_done;
+ bitmap = bitmap>>1;
+ bit++;
}
- bitmap = bitmap>>1;
- bit++;
- }
-
setfilparam_done:
- if (isad) {
- ad_flush( adp, ADFLAGS_HF );
- ad_close( adp, ADFLAGS_HF );
+ if (isad) {
+ ad_flush( adp, ADFLAGS_HF );
+ ad_close( adp, ADFLAGS_HF );
#ifdef FORCE_UIDGID
- restore_uidgid ( uidgid );
+ restore_uidgid ( uidgid );
#endif /* FORCE_UIDGID */
- }
+ }
#ifdef DEBUG
- LOG(log_info, logtype_default, "end setfilparams:");
+ LOG(log_info, logtype_default, "end setfilparams:");
#endif /* DEBUG */
- return err;
-}
-
-/*
- * renamefile and copyfile take the old and new unix pathnames
- * and the new mac name.
- * NOTE: if we have to copy a file instead of renaming it, locks
- * will break.
- */
-int renamefile(src, dst, newname, noadouble )
-char *src, *dst, *newname;
-const int noadouble;
-{
- struct adouble ad;
- char adsrc[ MAXPATHLEN + 1];
- int len, rc;
+ return err;
+ }
/*
- * Note that this is only checking the existance of the data file,
- * not the header file. The thinking is that if the data file doesn't
- * exist, but the header file does, the right thing to do is remove
- * the data file silently.
+ * renamefile and copyfile take the old and new unix pathnames
+ * and the new mac name.
+ * NOTE: if we have to copy a file instead of renaming it, locks
+ * will break.
*/
+ int renamefile(src, dst, newname, noadouble )
+ char *src, *dst, *newname;
+ const int noadouble;
+ {
+ struct adouble ad;
+ char adsrc[ MAXPATHLEN + 1];
+ int len, rc;
+
+ /*
+ * Note that this is only checking the existance of the data file,
+ * not the header file. The thinking is that if the data file doesn't
+ * exist, but the header file does, the right thing to do is remove
+ * the data file silently.
+ */
- /* existence check moved to afp_moveandrename */
+ /* existence check moved to afp_moveandrename */
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin renamefile:");
+ LOG(log_info, logtype_default, "begin renamefile:");
#endif /* DEBUG */
- if ( rename( src, dst ) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EPERM:
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- case EXDEV : /* Cross device move -- try copy */
- if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) {
- deletefile( dst );
- return( rc );
+ if ( rename( src, dst ) < 0 ) {
+ switch ( errno ) {
+ case ENOENT :
+ return( AFPERR_NOOBJ );
+ case EPERM:
+ case EACCES :
+ return( AFPERR_ACCESS );
+ case EROFS:
+ return AFPERR_VLOCK;
+ case EXDEV : /* Cross device move -- try copy */
+ if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) {
+ deletefile( dst );
+ return( rc );
+ }
+ return deletefile( src );
+ default :
+ return( AFPERR_PARAM );
}
- return deletefile( src );
- default :
- return( AFPERR_PARAM );
}
- }
- strcpy( adsrc, ad_path( src, 0 ));
- rc = 0;
+ strcpy( adsrc, ad_path( src, 0 ));
+ rc = 0;
rename_retry:
- if (rename( adsrc, ad_path( dst, 0 )) < 0 ) {
- struct stat st;
+ if (rename( adsrc, ad_path( dst, 0 )) < 0 ) {
+ struct stat st;
- switch ( errno ) {
- case ENOENT :
- /* check for a source appledouble header. if it exists, make
- * a dest appledouble directory and do the rename again. */
- memset(&ad, 0, sizeof(ad));
- if (rc || stat(adsrc, &st) ||
- (ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad) < 0))
- return AFP_OK;
- rc++;
- ad_close(&ad, ADFLAGS_HF);
- goto rename_retry;
- case EPERM:
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
+ switch ( errno ) {
+ case ENOENT :
+ /* check for a source appledouble header. if it exists, make
+ * a dest appledouble directory and do the rename again. */
+ memset(&ad, 0, sizeof(ad));
+ if (rc || stat(adsrc, &st) ||
+ (ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad) < 0))
+ return AFP_OK;
+ rc++;
+ ad_close(&ad, ADFLAGS_HF);
+ goto rename_retry;
+ case EPERM:
+ case EACCES :
+ return( AFPERR_ACCESS );
+ case EROFS:
+ return AFPERR_VLOCK;
+ default :
+ return( AFPERR_PARAM );
+ }
}
- }
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( dst, ADFLAGS_HF, O_RDWR, 0666, &ad) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
+ memset(&ad, 0, sizeof(ad));
+ if ( ad_open( dst, ADFLAGS_HF, O_RDWR, 0666, &ad) < 0 ) {
+ switch ( errno ) {
+ case ENOENT :
+ return( AFPERR_NOOBJ );
+ case EACCES :
+ return( AFPERR_ACCESS );
+ case EROFS:
+ return AFPERR_VLOCK;
+ 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 );
+ 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
- LOG(log_info, logtype_default, "end renamefile:");
+ LOG(log_info, logtype_default, "end renamefile:");
#endif /* DEBUG */
- return( AFP_OK );
-}
+ return( AFP_OK );
+ }
-int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct vol *vol;
- struct dir *dir;
- char *newname, *path, *p;
- u_int32_t sdid, ddid;
- int plen, err, retvalue = AFP_OK;
- u_int16_t svid, dvid;
+ int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct vol *vol;
+ struct dir *dir;
+ char *newname, *path, *p;
+ u_int32_t sdid, ddid;
+ int plen, err, retvalue = AFP_OK;
+ u_int16_t svid, dvid;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_copyfile:");
+ LOG(log_info, logtype_default, "begin afp_copyfile:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&svid, ibuf, sizeof( svid ));
- ibuf += sizeof( svid );
- if (( vol = getvolbyvid( svid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ memcpy(&svid, ibuf, sizeof( svid ));
+ ibuf += sizeof( svid );
+ if (( vol = getvolbyvid( svid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- memcpy(&sdid, ibuf, sizeof( sdid ));
- ibuf += sizeof( sdid );
- if (( dir = dirsearch( vol, sdid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ memcpy(&sdid, ibuf, sizeof( sdid ));
+ ibuf += sizeof( sdid );
+ if (( dir = dirsearch( vol, sdid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- memcpy(&dvid, ibuf, sizeof( dvid ));
- ibuf += sizeof( dvid );
- memcpy(&ddid, ibuf, sizeof( ddid ));
- ibuf += sizeof( ddid );
+ memcpy(&dvid, ibuf, sizeof( dvid ));
+ ibuf += sizeof( dvid );
+ memcpy(&ddid, ibuf, sizeof( ddid ));
+ ibuf += sizeof( ddid );
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
- if ( *path == '\0' ) {
- return( AFPERR_BADTYPE );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
+ if ( *path == '\0' ) {
+ return( AFPERR_BADTYPE );
+ }
- /* don't allow copies when the file is open.
- * XXX: the spec only calls for read/deny write access.
- * however, copyfile doesn't have any of that info,
- * and locks need to stay coherent. as a result,
- * we just balk if the file is opened already. */
- if (of_findname(vol, curdir, path))
- return AFPERR_DENYCONF;
+ /* don't allow copies when the file is open.
+ * XXX: the spec only calls for read/deny write access.
+ * however, copyfile doesn't have any of that info,
+ * and locks need to stay coherent. as a result,
+ * we just balk if the file is opened already. */
+ if (of_findname(vol, curdir, path))
+ return AFPERR_DENYCONF;
- newname = obj->newtmp;
- strcpy( newname, path );
+ newname = obj->newtmp;
+ strcpy( newname, path );
- p = ctoupath( vol, curdir, newname );
+ p = ctoupath( vol, curdir, newname );
- if (( vol = getvolbyvid( dvid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( vol = getvolbyvid( dvid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- if (( dir = dirsearch( vol, ddid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( dir = dirsearch( vol, ddid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
- if ( *path != '\0' ) {
- return( AFPERR_BADTYPE );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
+ if ( *path != '\0' ) {
+ return( AFPERR_BADTYPE );
+ }
- /* one of the handful of places that knows about the path type */
- if ( *ibuf++ != 2 ) {
- return( AFPERR_PARAM );
- }
- if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
- strncpy( newname, ibuf, plen );
- newname[ plen ] = '\0';
- }
+ /* one of the handful of places that knows about the path type */
+ if ( *ibuf++ != 2 ) {
+ return( AFPERR_PARAM );
+ }
+ if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
+ strncpy( newname, ibuf, plen );
+ newname[ plen ] = '\0';
+ }
- if ( (err = copyfile(p, mtoupath(vol, newname ), newname,
- vol_noadouble(vol))) < 0 ) {
- return err;
- }
+ if ( (err = copyfile(p, mtoupath(vol, newname ), newname,
+ vol_noadouble(vol))) < 0 ) {
+ return err;
+ }
- setvoltime(obj, vol );
+ setvoltime(obj, vol );
#ifdef DROPKLUDGE
- if (vol->v_flags & AFPVOL_DROPBOX) {
- retvalue=matchfile2dirperms(newname, vol, sdid);
- }
+ if (vol->v_flags & AFPVOL_DROPBOX) {
+ retvalue=matchfile2dirperms(newname, vol, sdid);
+ }
#endif /* DROPKLUDGE */
#ifdef DEBUG
- LOG(log_info, logtype_default, "end afp_copyfile:");
+ LOG(log_info, logtype_default, "end afp_copyfile:");
#endif /* DEBUG */
- return( retvalue );
-}
+ return( retvalue );
+ }
-static __inline__ int copy_all(const int dfd, const void *buf,
- size_t buflen)
-{
- ssize_t cc;
+ static __inline__ int copy_all(const int dfd, const void *buf,
+ size_t buflen)
+ {
+ ssize_t cc;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin copy_all:");
+ LOG(log_info, logtype_default, "begin copy_all:");
#endif /* DEBUG */
- while (buflen > 0) {
- if ((cc = write(dfd, buf, buflen)) < 0) {
- switch (errno) {
- case EINTR:
- continue;
- case EDQUOT:
- case EFBIG:
- case ENOSPC:
- return AFPERR_DFULL;
- case EROFS:
- return AFPERR_VLOCK;
- default:
- return AFPERR_PARAM;
+ while (buflen > 0) {
+ if ((cc = write(dfd, buf, buflen)) < 0) {
+ switch (errno) {
+ case EINTR:
+ continue;
+ case EDQUOT:
+ case EFBIG:
+ case ENOSPC:
+ return AFPERR_DFULL;
+ case EROFS:
+ return AFPERR_VLOCK;
+ default:
+ return AFPERR_PARAM;
+ }
}
+ buflen -= cc;
}
- buflen -= cc;
- }
#ifdef DEBUG
- LOG(log_info, logtype_default, "end copy_all:");
+ LOG(log_info, logtype_default, "end copy_all:");
#endif /* DEBUG */
- return AFP_OK;
-}
+ return AFP_OK;
+ }
-/* XXX: this needs to use ad_open and ad_lock. so, we need to
- * pass in vol and path */
-int copyfile(src, dst, newname, noadouble )
-char *src, *dst, *newname;
-const int noadouble;
-{
- struct adouble ad;
- struct stat st;
- char filebuf[8192];
- int sfd, dfd, len, err = AFP_OK;
- ssize_t cc;
+ /* XXX: this needs to use ad_open and ad_lock. so, we need to
+ * pass in vol and path */
+ int copyfile(src, dst, newname, noadouble )
+ char *src, *dst, *newname;
+ const int noadouble;
+ {
+ struct adouble ad;
+ struct stat st;
+ char filebuf[8192];
+ int sfd, dfd, len, err = AFP_OK;
+ ssize_t cc;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin copyfile:");
+ LOG(log_info, logtype_default, "begin copyfile:");
#endif /* DEBUG */
- 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( ad_path( dst, ADFLAGS_HF ), O_WRONLY|O_CREAT,
- ad_mode( ad_path( dst, ADFLAGS_HF ), 0666 ))) < 0 ) {
- close( sfd );
+ if (newname) {
+ if ((sfd = open( ad_path( src, ADFLAGS_HF ), O_RDONLY, 0 )) < 0 ) {
switch ( errno ) {
case ENOENT :
- return( AFPERR_NOOBJ );
+ break; /* just copy the data fork */
case EACCES :
return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
default :
return( AFPERR_PARAM );
}
- }
+ } else {
+ if (( dfd = open( ad_path( dst, ADFLAGS_HF ), O_WRONLY|O_CREAT,
+ ad_mode( ad_path( dst, ADFLAGS_HF ), 0666 ))) < 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 */
+ /* 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;
+ 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;
}
- 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;
- }
+ 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 (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0))
+ break;
+ }
copyheader_done:
- close(sfd);
- close(dfd);
- if (err < 0) {
- unlink(ad_path(dst, ADFLAGS_HF));
- return err;
+ close(sfd);
+ close(dfd);
+ if (err < 0) {
+ unlink(ad_path(dst, ADFLAGS_HF));
+ return err;
+ }
}
}
- }
- /* data fork copying */
- if (( sfd = open( src, O_RDONLY, 0 )) < 0 ) {
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EACCES :
- return( AFPERR_ACCESS );
- default :
- return( AFPERR_PARAM );
+ /* data fork copying */
+ if (( sfd = open( src, O_RDONLY, 0 )) < 0 ) {
+ switch ( errno ) {
+ case ENOENT :
+ return( AFPERR_NOOBJ );
+ case EACCES :
+ return( AFPERR_ACCESS );
+ default :
+ return( AFPERR_PARAM );
+ }
}
- }
- if (( dfd = open( dst, O_WRONLY|O_CREAT, ad_mode( dst, 0666 ))) < 0 ) {
- close( sfd );
- switch ( errno ) {
- case ENOENT :
- return( AFPERR_NOOBJ );
- case EACCES :
- return( AFPERR_ACCESS );
- case EROFS:
- return AFPERR_VLOCK;
- default :
- return( AFPERR_PARAM );
+ if (( dfd = open( dst, O_WRONLY|O_CREAT, ad_mode( dst, 0666 ))) < 0 ) {
+ close( sfd );
+ switch ( errno ) {
+ case ENOENT :
+ return( AFPERR_NOOBJ );
+ case EACCES :
+ return( AFPERR_ACCESS );
+ case EROFS:
+ return AFPERR_VLOCK;
+ default :
+ 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;
+ 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;
}
- goto copydata_done;
- }
#endif /* SENDFILE_FLAVOR_LINUX */
- while (1) {
- if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) {
- if (errno == EINTR)
- continue;
+ while (1) {
+ if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) {
+ if (errno == EINTR)
+ continue;
- err = AFPERR_PARAM;
- break;
- }
+ err = AFPERR_PARAM;
+ break;
+ }
- if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) {
- break;
+ if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) {
+ break;
+ }
}
- }
copydata_done:
- close(sfd);
- close(dfd);
- if (err < 0) {
- unlink(ad_path(dst, ADFLAGS_HF));
- unlink(dst);
- return err;
- }
+ close(sfd);
+ close(dfd);
+ if (err < 0) {
+ unlink(ad_path(dst, ADFLAGS_HF));
+ unlink(dst);
+ return err;
+ }
- 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 (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 );
+ }
}
- }
- 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 );
- }
+ 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
- LOG(log_info, logtype_default, "end copyfile:");
+ LOG(log_info, logtype_default, "end copyfile:");
#endif /* DEBUG */
- return( AFP_OK );
-}
+ return( AFP_OK );
+ }
-int deletefile( file )
-char *file;
-{
- struct adouble ad;
- int adflags, err = AFP_OK;
- int locktype = ADLOCK_WR;
- int openmode = O_RDWR;
+ int deletefile( file )
+ char *file;
+ {
+ struct adouble ad;
+ int adflags, err = AFP_OK;
+ int locktype = ADLOCK_WR;
+ int openmode = O_RDWR;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin deletefile:");
+ LOG(log_info, logtype_default, "begin deletefile:");
#endif /* DEBUG */
- while(1) {
- /*
- * If can't open read/write then try again read-only. If it's open
- * read-only, we must do a read lock instead of a write lock.
- */
- /* try to open both at once */
- adflags = ADFLAGS_DF|ADFLAGS_HF;
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) {
- switch (errno) {
- case ENOENT:
- adflags = ADFLAGS_DF;
- /* that failed. now try to open just the data fork */
- memset(&ad, 0, sizeof(ad));
- if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) {
- switch (errno) {
- case ENOENT:
- return AFPERR_NOOBJ;
- case EACCES:
- if(openmode == O_RDWR) {
- openmode = O_RDONLY;
- locktype = ADLOCK_RD;
- continue;
- } else {
- return AFPERR_ACCESS;
+ while(1) {
+ /*
+ * If can't open read/write then try again read-only. If it's open
+ * read-only, we must do a read lock instead of a write lock.
+ */
+ /* try to open both at once */
+ adflags = ADFLAGS_DF|ADFLAGS_HF;
+ memset(&ad, 0, sizeof(ad));
+ if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) {
+ switch (errno) {
+ case ENOENT:
+ adflags = ADFLAGS_DF;
+ /* that failed. now try to open just the data fork */
+ memset(&ad, 0, sizeof(ad));
+ if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) {
+ switch (errno) {
+ case ENOENT:
+ return AFPERR_NOOBJ;
+ case EACCES:
+ if(openmode == O_RDWR) {
+ openmode = O_RDONLY;
+ locktype = ADLOCK_RD;
+ continue;
+ } else {
+ return AFPERR_ACCESS;
+ }
+ case EROFS:
+ return AFPERR_VLOCK;
+ default:
+ return AFPERR_PARAM;
}
- case EROFS:
- return AFPERR_VLOCK;
- default:
- return AFPERR_PARAM;
}
- }
- break;
+ break;
- case EACCES:
- if(openmode == O_RDWR) {
- openmode = O_RDONLY;
- locktype = ADLOCK_RD;
- continue;
- } else {
- return AFPERR_ACCESS;
+ case EACCES:
+ if(openmode == O_RDWR) {
+ openmode = O_RDONLY;
+ locktype = ADLOCK_RD;
+ continue;
+ } else {
+ return AFPERR_ACCESS;
+ }
+ case EROFS:
+ return AFPERR_VLOCK;
+ default:
+ return( AFPERR_PARAM );
}
- case EROFS:
- return AFPERR_VLOCK;
- default:
- return( AFPERR_PARAM );
}
+ break; /* from the while */
}
- break; /* from the while */
- }
- if ((adflags & ADFLAGS_HF) &&
- (ad_tmplock(&ad, ADEID_RFORK, locktype, 0, 0) < 0 )) {
- ad_close( &ad, adflags );
- return( AFPERR_BUSY );
- }
-
- if (ad_tmplock( &ad, ADEID_DFORK, locktype, 0, 0 ) < 0) {
- err = AFPERR_BUSY;
- goto delete_unlock;
- }
+ if ((adflags & ADFLAGS_HF) &&
+ (ad_tmplock(&ad, ADEID_RFORK, locktype, 0, 0) < 0 )) {
+ ad_close( &ad, adflags );
+ return( AFPERR_BUSY );
+ }
- if ( unlink( ad_path( file, ADFLAGS_HF )) < 0 ) {
- switch ( errno ) {
- case EPERM:
- case EACCES :
- err = AFPERR_ACCESS;
- goto delete_unlock;
- case EROFS:
- err = AFPERR_VLOCK;
- goto delete_unlock;
- case ENOENT :
- break;
- default :
- err = AFPERR_PARAM;
+ if (ad_tmplock( &ad, ADEID_DFORK, locktype, 0, 0 ) < 0) {
+ err = AFPERR_BUSY;
goto delete_unlock;
}
- }
- if ( unlink( file ) < 0 ) {
- switch ( errno ) {
- case EPERM:
- case EACCES :
- err = AFPERR_ACCESS;
- break;
- case EROFS:
- err = AFPERR_VLOCK;
- break;
- case ENOENT :
- break;
- default :
- err = AFPERR_PARAM;
- break;
+ if ( unlink( ad_path( file, ADFLAGS_HF )) < 0 ) {
+ switch ( errno ) {
+ case EPERM:
+ case EACCES :
+ err = AFPERR_ACCESS;
+ goto delete_unlock;
+ case EROFS:
+ err = AFPERR_VLOCK;
+ goto delete_unlock;
+ case ENOENT :
+ break;
+ default :
+ err = AFPERR_PARAM;
+ goto delete_unlock;
+ }
+ }
+
+ if ( unlink( file ) < 0 ) {
+ switch ( errno ) {
+ case EPERM:
+ case EACCES :
+ err = AFPERR_ACCESS;
+ break;
+ case EROFS:
+ err = AFPERR_VLOCK;
+ break;
+ case ENOENT :
+ break;
+ default :
+ err = AFPERR_PARAM;
+ break;
+ }
}
- }
delete_unlock:
- if (adflags & ADFLAGS_HF)
- ad_tmplock(&ad, ADEID_RFORK, ADLOCK_CLR, 0, 0);
- ad_tmplock(&ad, ADEID_DFORK, ADLOCK_CLR, 0, 0);
- ad_close( &ad, adflags );
+ if (adflags & ADFLAGS_HF)
+ ad_tmplock(&ad, ADEID_RFORK, ADLOCK_CLR, 0, 0);
+ ad_tmplock(&ad, ADEID_DFORK, ADLOCK_CLR, 0, 0);
+ ad_close( &ad, adflags );
#ifdef DEBUG
- LOG(log_info, logtype_default, "end deletefile:");
+ LOG(log_info, logtype_default, "end deletefile:");
#endif /* DEBUG */
- return err;
-}
+ return err;
+ }
#ifdef CNID_DB
-/* return a file id */
-int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct stat st;
- struct adouble ad;
- struct vol *vol;
- struct dir *dir;
- char *path, *upath;
- int len;
- cnid_t did, id;
- u_short vid;
+ /* return a file id */
+ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct stat st;
+ struct adouble ad;
+ struct vol *vol;
+ struct dir *dir;
+ char *path, *upath;
+ int len;
+ cnid_t did, id;
+ u_short vid;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_createid:");
+ LOG(log_info, logtype_default, "begin afp_createid:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&vid, ibuf, sizeof(vid));
- ibuf += sizeof(vid);
+ memcpy(&vid, ibuf, sizeof(vid));
+ ibuf += sizeof(vid);
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM);
- }
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM);
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- memcpy(&did, ibuf, sizeof( did ));
- ibuf += sizeof(did);
+ memcpy(&did, ibuf, sizeof( did ));
+ ibuf += sizeof(did);
- if (( dir = dirsearch( vol, did )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if ( *path == '\0' ) {
- return( AFPERR_BADTYPE );
- }
+ if ( *path == '\0' ) {
+ return( AFPERR_BADTYPE );
+ }
- upath = mtoupath(vol, path);
- if (stat(upath, &st) < 0) {
- switch (errno) {
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- case ENOENT:
- return AFPERR_NOOBJ;
- default:
- return AFPERR_PARAM;
+ upath = mtoupath(vol, path);
+ if (stat(upath, &st) < 0) {
+ switch (errno) {
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ case ENOENT:
+ return AFPERR_NOOBJ;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
- if (id = cnid_lookup(vol->v_db, &st, did, upath, len = strlen(upath))) {
- memcpy(rbuf, &id, sizeof(id));
- *rbuflen = sizeof(id);
- return AFPERR_EXISTID;
- }
+ if (id = cnid_lookup(vol->v_db, &st, did, upath, len = strlen(upath))) {
+ memcpy(rbuf, &id, sizeof(id));
+ *rbuflen = sizeof(id);
+ return AFPERR_EXISTID;
+ }
#if AD_VERSION > AD_VERSION1
- memset(&ad, 0, sizeof(ad));
- if (ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, &ad ) >= 0) {
- memcpy(&id, ad_entry(&ad, ADEID_DID), sizeof(id));
- ad_close(&ad, ADFLAGS_HF);
- }
+ memset(&ad, 0, sizeof(ad));
+ if (ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, &ad ) >= 0) {
+ memcpy(&id, ad_entry(&ad, ADEID_DID), sizeof(id));
+ ad_close(&ad, ADFLAGS_HF);
+ }
#endif /* AD_VERSION > AD_VERSION1 */
- if (id = cnid_add(vol->v_db, &st, did, upath, len, id)) {
- memcpy(rbuf, &id, sizeof(id));
- *rbuflen = sizeof(id);
- return AFP_OK;
- }
+ if (id = cnid_add(vol->v_db, &st, did, upath, len, id)) {
+ memcpy(rbuf, &id, sizeof(id));
+ *rbuflen = sizeof(id);
+ return AFP_OK;
+ }
#ifdef DEBUG
- LOG(log_info, logtype_default, "ending afp_createid...:");
+ LOG(log_info, logtype_default, "ending afp_createid...:");
#endif /* DEBUG */
- switch (errno) {
- case EROFS:
- return AFPERR_VLOCK;
- break;
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- break;
- default:
- LOG(log_error, logtype_default, "afp_createid: cnid_add: %m");
- return AFPERR_PARAM;
+ switch (errno) {
+ case EROFS:
+ return AFPERR_VLOCK;
+ break;
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ break;
+ default:
+ LOG(log_error, logtype_default, "afp_createid: cnid_add: %s", strerror(errno));
+ return AFPERR_PARAM;
+ }
}
-}
-/* resolve a file id */
-int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct stat st;
- struct vol *vol;
- struct dir *dir;
- char *upath;
- int err, buflen;
- cnid_t id;
- u_int16_t vid, bitmap;
+ /* resolve a file id */
+ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct stat st;
+ struct vol *vol;
+ struct dir *dir;
+ char *upath;
+ int err, buflen;
+ cnid_t id;
+ u_int16_t vid, bitmap;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_resolveid:");
+ LOG(log_info, logtype_default, "begin afp_resolveid:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&vid, ibuf, sizeof(vid));
- ibuf += sizeof(vid);
+ memcpy(&vid, ibuf, sizeof(vid));
+ ibuf += sizeof(vid);
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM);
- }
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM);
+ }
- memcpy(&id, ibuf, sizeof( id ));
- ibuf += sizeof(id);
+ memcpy(&id, ibuf, sizeof( id ));
+ ibuf += sizeof(id);
- if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) {
- return AFPERR_BADID;
- }
+ if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) {
+ return AFPERR_BADID;
+ }
- if (( dir = dirsearch( vol, id )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( dir = dirsearch( vol, id )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) {
- switch (errno) {
- case EACCES:
- case EPERM:
- return AFPERR_ACCESS;
- case ENOENT:
- return AFPERR_NOID;
- default:
- return AFPERR_PARAM;
+ if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ return AFPERR_ACCESS;
+ case ENOENT:
+ return AFPERR_NOID;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
- /* directories are bad */
- if (S_ISDIR(st.st_mode))
- return AFPERR_BADTYPE;
+ /* directories are bad */
+ if (S_ISDIR(st.st_mode))
+ return AFPERR_BADTYPE;
- memcpy(&bitmap, ibuf, sizeof(bitmap));
- bitmap = ntohs( bitmap );
+ memcpy(&bitmap, ibuf, sizeof(bitmap));
+ bitmap = ntohs( bitmap );
- if ((err = getfilparams(vol, bitmap, utompath(vol, upath), curdir, &st,
- rbuf + sizeof(bitmap), &buflen)) != AFP_OK)
- return err;
+ if ((err = getfilparams(vol, bitmap, utompath(vol, upath), curdir, &st,
+ rbuf + sizeof(bitmap), &buflen)) != AFP_OK)
+ return err;
- *rbuflen = buflen + sizeof(bitmap);
- memcpy(rbuf, ibuf, sizeof(bitmap));
+ *rbuflen = buflen + sizeof(bitmap);
+ memcpy(rbuf, ibuf, sizeof(bitmap));
#ifdef DEBUG
- LOG(log_info, logtype_default, "end afp_resolveid:");
+ LOG(log_info, logtype_default, "end afp_resolveid:");
#endif /* DEBUG */
- return AFP_OK;
-}
+ return AFP_OK;
+ }
-int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct stat st;
- struct vol *vol;
- struct dir *dir;
- char *upath;
- int err;
- cnid_t id;
- u_short vid;
+ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct stat st;
+ struct vol *vol;
+ struct dir *dir;
+ char *upath;
+ int err;
+ cnid_t id;
+ u_short vid;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_deleteid:");
+ LOG(log_info, logtype_default, "begin afp_deleteid:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&vid, ibuf, sizeof(vid));
- ibuf += sizeof(vid);
+ memcpy(&vid, ibuf, sizeof(vid));
+ ibuf += sizeof(vid);
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM);
- }
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM);
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- memcpy(&id, ibuf, sizeof( id ));
- ibuf += sizeof(id);
+ memcpy(&id, ibuf, sizeof( id ));
+ ibuf += sizeof(id);
- if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) {
- return AFPERR_NOID;
- }
+ if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) {
+ return AFPERR_NOID;
+ }
- if (( dir = dirsearch( vol, id )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( dir = dirsearch( vol, id )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- err = AFP_OK;
- if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) {
- switch (errno) {
- case EACCES:
- case EPERM:
- return AFPERR_ACCESS;
- case ENOENT:
- /* still try to delete the id */
- err = AFPERR_NOOBJ;
- break;
- default:
- return AFPERR_PARAM;
+ err = AFP_OK;
+ if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ return AFPERR_ACCESS;
+ case ENOENT:
+ /* still try to delete the id */
+ err = AFPERR_NOOBJ;
+ break;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
- /* directories are bad */
- if (S_ISDIR(st.st_mode))
- return AFPERR_BADTYPE;
+ /* directories are bad */
+ if (S_ISDIR(st.st_mode))
+ return AFPERR_BADTYPE;
- if (cnid_delete(vol->v_db, id)) {
- switch (errno) {
- case EROFS:
- return AFPERR_VLOCK;
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- default:
- return AFPERR_PARAM;
+ if (cnid_delete(vol->v_db, id)) {
+ switch (errno) {
+ case EROFS:
+ return AFPERR_VLOCK;
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
#ifdef DEBUG
- LOG(log_info, logtype_default, "end afp_deleteid:");
+ LOG(log_info, logtype_default, "end afp_deleteid:");
#endif /* DEBUG */
- return err;
-}
+ return err;
+ }
#endif /* CNID_DB */
#define APPLETEMP ".AppleTempXXXXXX"
-int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct stat srcst, destst;
- struct vol *vol;
- struct dir *dir, *sdir;
- char *spath, temp[17], *path, *p;
- char *supath, *upath;
- int err;
+ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct stat srcst, destst;
+ struct vol *vol;
+ struct dir *dir, *sdir;
+ char *spath, temp[17], *path, *p;
+ char *supath, *upath;
+ int err;
#ifdef CNID_DB
- int slen, dlen;
+ int slen, dlen;
#endif /* CNID_DB */
- u_int32_t sid, did;
- u_int16_t vid;
+ u_int32_t sid, did;
+ u_int16_t vid;
#ifdef DEBUG
- LOG(log_info, logtype_default, "begin afp_exchangefiles:");
+ LOG(log_info, logtype_default, "begin afp_exchangefiles:");
#endif /* DEBUG */
- *rbuflen = 0;
- ibuf += 2;
+ *rbuflen = 0;
+ ibuf += 2;
- memcpy(&vid, ibuf, sizeof(vid));
- ibuf += sizeof(vid);
+ memcpy(&vid, ibuf, sizeof(vid));
+ ibuf += sizeof(vid);
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM);
- }
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM);
+ }
- if (vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ if (vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- /* source and destination dids */
- memcpy(&sid, ibuf, sizeof(sid));
- ibuf += sizeof(sid);
- memcpy(&did, ibuf, sizeof(did));
- ibuf += sizeof(did);
+ /* source and destination dids */
+ memcpy(&sid, ibuf, sizeof(sid));
+ ibuf += sizeof(sid);
+ memcpy(&did, ibuf, sizeof(did));
+ ibuf += sizeof(did);
- /* source file */
- if ((dir = dirsearch( vol, sid )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ /* source file */
+ if ((dir = dirsearch( vol, sid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if ( *path == '\0' ) {
- return( AFPERR_BADTYPE );
- }
+ if ( *path == '\0' ) {
+ return( AFPERR_BADTYPE );
+ }
- upath = mtoupath(vol, path);
- if (stat(upath, &srcst) < 0) {
- switch (errno) {
- case ENOENT:
- return AFPERR_NOID;
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- default:
- return AFPERR_PARAM;
+ upath = mtoupath(vol, path);
+ if (stat(upath, &srcst) < 0) {
+ switch (errno) {
+ case ENOENT:
+ return AFPERR_NOID;
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
- /* save some stuff */
- sdir = curdir;
- spath = obj->oldtmp;
- supath = obj->newtmp;
- strcpy(spath, path);
- strcpy(supath, upath); /* this is for the cnid changing */
- p = ctoupath( vol, sdir, spath);
+ /* save some stuff */
+ sdir = curdir;
+ spath = obj->oldtmp;
+ supath = obj->newtmp;
+ strcpy(spath, path);
+ strcpy(supath, upath); /* this is for the cnid changing */
+ p = ctoupath( vol, sdir, spath);
- /* look for the source cnid. if it doesn't exist, don't worry about
- * it. */
+ /* look for the source cnid. if it doesn't exist, don't worry about
+ * it. */
#ifdef CNID_DB
- sid = cnid_lookup(vol->v_db, &srcst, sdir->d_did, supath,
- slen = strlen(supath));
+ sid = cnid_lookup(vol->v_db, &srcst, sdir->d_did, supath,
+ slen = strlen(supath));
#endif /* CNID_DB */
- if (( dir = dirsearch( vol, did )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_PARAM );
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- if ( *path == '\0' ) {
- return( AFPERR_BADTYPE );
- }
+ if ( *path == '\0' ) {
+ return( AFPERR_BADTYPE );
+ }
- /* FPExchangeFiles is the only call that can return the SameObj
- * error */
- if ((curdir == sdir) && strcmp(spath, path) == 0)
- return AFPERR_SAMEOBJ;
+ /* FPExchangeFiles is the only call that can return the SameObj
+ * error */
+ if ((curdir == sdir) && strcmp(spath, path) == 0)
+ return AFPERR_SAMEOBJ;
- upath = mtoupath(vol, path);
- if (stat(upath, &destst) < 0) {
- switch (errno) {
- case ENOENT:
- return AFPERR_NOID;
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- default:
- return AFPERR_PARAM;
+ upath = mtoupath(vol, path);
+ if (stat(upath, &destst) < 0) {
+ switch (errno) {
+ case ENOENT:
+ return AFPERR_NOID;
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ default:
+ return AFPERR_PARAM;
+ }
}
- }
#ifdef CNID_DB
- /* look for destination id. */
- did = cnid_lookup(vol->v_db, &destst, curdir->d_did, upath,
- dlen = strlen(upath));
+ /* look for destination id. */
+ did = cnid_lookup(vol->v_db, &destst, curdir->d_did, upath,
+ dlen = strlen(upath));
#endif /* CNID_DB */
- /* construct a temp name.
- * NOTE: the temp file will be in the dest file's directory. it
- * will also be inaccessible from AFP. */
- memcpy(temp, APPLETEMP, sizeof(APPLETEMP));
- if (!mktemp(temp))
- return AFPERR_MISC;
+ /* construct a temp name.
+ * NOTE: the temp file will be in the dest file's directory. it
+ * will also be inaccessible from AFP. */
+ memcpy(temp, APPLETEMP, sizeof(APPLETEMP));
+ if (!mktemp(temp))
+ return AFPERR_MISC;
- /* now, quickly rename the file. we error if we can't. */
- if ((err = renamefile(p, temp, temp, vol_noadouble(vol))) < 0)
- goto err_exchangefile;
- of_rename(vol, sdir, spath, curdir, temp);
+ /* now, quickly rename the file. we error if we can't. */
+ if ((err = renamefile(p, temp, temp, vol_noadouble(vol))) < 0)
+ goto err_exchangefile;
+ of_rename(vol, sdir, spath, curdir, temp);
- /* rename destination to source */
- if ((err = renamefile(path, p, spath, vol_noadouble(vol))) < 0)
- goto err_src_to_tmp;
- of_rename(vol, curdir, path, sdir, spath);
+ /* rename destination to source */
+ if ((err = renamefile(path, p, spath, vol_noadouble(vol))) < 0)
+ goto err_src_to_tmp;
+ of_rename(vol, curdir, path, sdir, spath);
- /* rename temp to destination */
- if ((err = renamefile(temp, upath, path, vol_noadouble(vol))) < 0)
- goto err_dest_to_src;
- of_rename(vol, curdir, temp, curdir, path);
+ /* rename temp to destination */
+ if ((err = renamefile(temp, upath, path, vol_noadouble(vol))) < 0)
+ goto err_dest_to_src;
+ of_rename(vol, curdir, temp, curdir, path);
#ifdef CNID_DB
- /* id's need switching. src -> dest and dest -> src. */
- if (sid && (cnid_update(vol->v_db, sid, &destst, curdir->d_did,
- upath, dlen) < 0)) {
- switch (errno) {
- case EPERM:
- case EACCES:
- err = AFPERR_ACCESS;
- break;
- default:
- err = AFPERR_PARAM;
+ /* id's need switching. src -> dest and dest -> src. */
+ if (sid && (cnid_update(vol->v_db, sid, &destst, curdir->d_did,
+ upath, dlen) < 0)) {
+ switch (errno) {
+ case EPERM:
+ case EACCES:
+ err = AFPERR_ACCESS;
+ break;
+ default:
+ err = AFPERR_PARAM;
+ }
+ goto err_temp_to_dest;
}
- goto err_temp_to_dest;
- }
- if (did && (cnid_update(vol->v_db, did, &srcst, sdir->d_did,
- supath, slen) < 0)) {
- switch (errno) {
- case EPERM:
- case EACCES:
- err = AFPERR_ACCESS;
- break;
- default:
- err = AFPERR_PARAM;
- }
+ if (did && (cnid_update(vol->v_db, did, &srcst, sdir->d_did,
+ supath, slen) < 0)) {
+ switch (errno) {
+ case EPERM:
+ case EACCES:
+ err = AFPERR_ACCESS;
+ break;
+ default:
+ err = AFPERR_PARAM;
+ }
- if (sid)
- cnid_update(vol->v_db, sid, &srcst, sdir->d_did, supath, slen);
- goto err_temp_to_dest;
- }
+ if (sid)
+ cnid_update(vol->v_db, sid, &srcst, sdir->d_did, supath, slen);
+ goto err_temp_to_dest;
+ }
#endif /* CNID_DB */
#ifdef DEBUG
- LOG(log_info, logtype_default, "ending afp_exchangefiles:");
+ LOG(log_info, logtype_default, "ending afp_exchangefiles:");
#endif /* DEBUG */
- return AFP_OK;
+ return AFP_OK;
- /* all this stuff is so that we can unwind a failed operation
- * properly. */
+ /* all this stuff is so that we can unwind a failed operation
+ * properly. */
err_temp_to_dest:
- /* rename dest to temp */
- renamefile(upath, temp, temp, vol_noadouble(vol));
- of_rename(vol, curdir, upath, curdir, temp);
+ /* rename dest to temp */
+ renamefile(upath, temp, temp, vol_noadouble(vol));
+ of_rename(vol, curdir, upath, curdir, temp);
err_dest_to_src:
- /* rename source back to dest */
- renamefile(p, upath, path, vol_noadouble(vol));
- of_rename(vol, sdir, spath, curdir, path);
+ /* rename source back to dest */
+ renamefile(p, upath, path, vol_noadouble(vol));
+ of_rename(vol, sdir, spath, curdir, path);
err_src_to_tmp:
- /* rename temp back to source */
- renamefile(temp, p, spath, vol_noadouble(vol));
- of_rename(vol, curdir, temp, sdir, spath);
+ /* rename temp back to source */
+ renamefile(temp, p, spath, vol_noadouble(vol));
+ of_rename(vol, curdir, temp, sdir, spath);
err_exchangefile:
- return err;
-}
+ return err;
+ }
/*
- * $Id: fork.c,v 1.15 2002-01-16 19:55:15 jmarcus Exp $
+ * $Id: fork.c,v 1.16 2002-01-17 16:19:06 jmarcus Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
const u_int16_t attrbits;
{
#ifndef USE_LASTDID
- struct stat hst, lst, *lstp;
+ struct stat hst, lst, *lstp;
#else /* USE_LASTDID */
- struct stat hst;
+ struct stat hst;
#endif
struct stat st;
struct extmap *em;
aint = cnid_add(ofork->of_vol->v_db, &st,
ofork->of_dir->d_did,
upath, strlen(upath), aint);
+ if (aint > CNID_MAX) {
+ switch (aint) {
+ case CNID_ERR_PARAM:
+ LOG(log_error, logtype_default, "getforkparams: Incorrect parameters passed to cnid_add");
+ return(AFPERR_PARAM);
+ case CNID_ERR_PATH:
+ return(AFPERR_PARAM);
+ case CNID_ERR_DB:
+ case CNID_ERR_MAX:
+ return(AFPERR_MISC);
+ }
#endif /* CNID_DB */
- if (aint == 0) {
+ if (aint == 0) {
#ifdef USE_LASTDID
- aint = htonl(( st.st_dev << 16 ) | ( st.st_ino & 0x0000ffff ));
+ aint = htonl(( st.st_dev << 16 ) | ( st.st_ino & 0x0000ffff ));
#else /* USE_LASTDID */
- lstp = lstat(upath, &lst) < 0 ? st : &lst;
+ lstp = lstat(upath, &lst) < 0 ? st : &lst;
#ifdef DID_MTAB
- aint = htonl( afpd_st_cnid ( lstp ) );
+ aint = htonl( afpd_st_cnid ( lstp ) );
#else /* DID_MTAB */
- aint = htonl(CNID(lstp, 1));
+ aint = htonl(CNID(lstp, 1));
#endif /* DID_MTAB */
#endif /* USE_LASTDID */
- }
+ }
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
- case FILPBIT_DFLEN :
- aint = htonl( st.st_size );
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
+ case FILPBIT_DFLEN :
+ aint = htonl( st.st_size );
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
- case FILPBIT_RFLEN :
- if ( isad ) {
- aint = htonl( ad_getentrylen( ofork->of_ad, ADEID_RFORK ));
- } else {
- aint = 0;
- }
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
+ case FILPBIT_RFLEN :
+ if ( isad ) {
+ aint = htonl( ad_getentrylen( ofork->of_ad, ADEID_RFORK ));
+ } else {
+ aint = 0;
+ }
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
- default :
- return( AFPERR_BITMAP );
+ default :
+ return( AFPERR_BITMAP );
+ }
+ bitmap = bitmap>>1;
+ bit++;
}
- bitmap = bitmap>>1;
- bit++;
- }
-
- if ( nameoff ) {
- ashort = htons( data - buf );
- memcpy(nameoff, &ashort, sizeof( ashort ));
- aint = strlen( ofork->of_name );
- aint = ( aint > MACFILELEN ) ? MACFILELEN : aint;
- *data++ = aint;
- memcpy(data, ofork->of_name, aint );
- data += aint;
- }
- *buflen = data - buf;
- return( AFP_OK );
-}
+ if ( nameoff ) {
+ ashort = htons( data - buf );
+ memcpy(nameoff, &ashort, sizeof( ashort ));
+ aint = strlen( ofork->of_name );
+ aint = ( aint > MACFILELEN ) ? MACFILELEN : aint;
+ *data++ = aint;
+ memcpy(data, ofork->of_name, aint );
+ data += aint;
+ }
-int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct vol *vol;
- struct dir *dir;
- struct ofork *ofork, *opened;
- struct adouble *adsame = NULL;
- int buflen, ret, adflags, eid, lockop;
- u_int32_t did;
- u_int16_t vid, bitmap, access, ofrefnum, attrbits = 0;
- char fork, *path, *upath;
-
- ibuf++;
- fork = *ibuf++;
- memcpy(&vid, ibuf, sizeof( vid ));
- ibuf += sizeof(vid);
-
- *rbuflen = 0;
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM );
+ *buflen = data - buf;
+ return( AFP_OK );
}
- memcpy(&did, ibuf, sizeof( did ));
- ibuf += sizeof( int );
+ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct vol *vol;
+ struct dir *dir;
+ struct ofork *ofork, *opened;
+ struct adouble *adsame = NULL;
+ int buflen, ret, adflags, eid, lockop;
+ u_int32_t did;
+ u_int16_t vid, bitmap, access, ofrefnum, attrbits = 0;
+ char fork, *path, *upath;
+
+ ibuf++;
+ fork = *ibuf++;
+ memcpy(&vid, ibuf, sizeof( vid ));
+ ibuf += sizeof(vid);
- if (( dir = dirsearch( vol, did )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ *rbuflen = 0;
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- memcpy(&bitmap, ibuf, sizeof( bitmap ));
- bitmap = ntohs( bitmap );
- ibuf += sizeof( bitmap );
- memcpy(&access, ibuf, sizeof( access ));
- access = ntohs( access );
- ibuf += sizeof( access );
+ memcpy(&did, ibuf, sizeof( did ));
+ ibuf += sizeof( int );
- if ((vol->v_flags & AFPVOL_RO) && (access & OPENACC_WR)) {
- return AFPERR_VLOCK;
- }
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
- }
+ memcpy(&bitmap, ibuf, sizeof( bitmap ));
+ bitmap = ntohs( bitmap );
+ ibuf += sizeof( bitmap );
+ memcpy(&access, ibuf, sizeof( access ));
+ access = ntohs( access );
+ ibuf += sizeof( access );
- if ( fork == OPENFORK_DATA ) {
- eid = ADEID_DFORK;
- adflags = ADFLAGS_DF|ADFLAGS_HF;
- } else {
- eid = ADEID_RFORK;
- adflags = ADFLAGS_HF;
- }
+ if ((vol->v_flags & AFPVOL_RO) && (access & OPENACC_WR)) {
+ return AFPERR_VLOCK;
+ }
- /* XXX: this probably isn't the best way to do this. the already
- open bits should really be set if the fork is opened by any
- program, not just this one. however, that's problematic to do
- if we can't write lock files somewhere. opened is also passed to
- ad_open so that we can keep file locks together. */
- if ((opened = of_findname(vol, curdir, path))) {
- attrbits = ((opened->of_flags & AFPFORK_RSRC) ? ATTRBIT_ROPEN : 0) |
- ((opened->of_flags & AFPFORK_DATA) ? ATTRBIT_DOPEN : 0);
- adsame = opened->of_ad;
- }
+ if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+ return( AFPERR_NOOBJ );
+ }
- if (( ofork = of_alloc(vol, curdir, path, &ofrefnum, eid,
- adsame)) == NULL ) {
- return( AFPERR_NFILE );
- }
- if (access & OPENACC_WR) {
- /* try opening in read-write mode */
- upath = mtoupath(vol, path);
- ret = AFPERR_NOOBJ;
- if (ad_open(upath, adflags, O_RDWR, 0, ofork->of_ad) < 0) {
- switch ( errno ) {
- case EROFS:
- ret = AFPERR_VLOCK;
- case EACCES:
- goto openfork_err;
+ if ( fork == OPENFORK_DATA ) {
+ eid = ADEID_DFORK;
+ adflags = ADFLAGS_DF|ADFLAGS_HF;
+ } else {
+ eid = ADEID_RFORK;
+ adflags = ADFLAGS_HF;
+ }
- break;
- case ENOENT:
- {
- struct stat st;
+ /* XXX: this probably isn't the best way to do this. the already
+ open bits should really be set if the fork is opened by any
+ program, not just this one. however, that's problematic to do
+ if we can't write lock files somewhere. opened is also passed to
+ ad_open so that we can keep file locks together. */
+ if ((opened = of_findname(vol, curdir, path))) {
+ attrbits = ((opened->of_flags & AFPFORK_RSRC) ? ATTRBIT_ROPEN : 0) |
+ ((opened->of_flags & AFPFORK_DATA) ? ATTRBIT_DOPEN : 0);
+ adsame = opened->of_ad;
+ }
- /* see if client asked for the data fork */
- if (fork == OPENFORK_DATA) {
- if (ad_open(upath, ADFLAGS_DF, O_RDWR, 0, ofork->of_ad) < 0) {
- goto openfork_err;
- }
- adflags = ADFLAGS_DF;
+ if (( ofork = of_alloc(vol, curdir, path, &ofrefnum, eid,
+ adsame)) == NULL ) {
+ return( AFPERR_NFILE );
+ }
+ if (access & OPENACC_WR) {
+ /* try opening in read-write mode */
+ upath = mtoupath(vol, path);
+ ret = AFPERR_NOOBJ;
+ if (ad_open(upath, adflags, O_RDWR, 0, ofork->of_ad) < 0) {
+ switch ( errno ) {
+ case EROFS:
+ ret = AFPERR_VLOCK;
+ case EACCES:
+ goto openfork_err;
- } else if (stat(upath, &st) == 0) {
- /* here's the deal. we only try to create the resource
- * 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)
+ break;
+ case ENOENT:
+ {
+ struct stat st;
+
+ /* see if client asked for the data fork */
+ if (fork == OPENFORK_DATA) {
+ if (ad_open(upath, ADFLAGS_DF, O_RDWR, 0, ofork->of_ad) < 0) {
+ goto openfork_err;
+ }
+ adflags = ADFLAGS_DF;
+
+ } else if (stat(upath, &st) == 0) {
+ /* here's the deal. we only try to create the resource
+ * 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;
+ } else
goto openfork_err;
- } else
- goto openfork_err;
+ }
+ break;
+ case EMFILE :
+ case ENFILE :
+ ret = AFPERR_NFILE;
+ goto openfork_err;
+ break;
+ case EISDIR :
+ ret = AFPERR_BADTYPE;
+ goto openfork_err;
+ break;
+ default:
+ LOG(log_error, logtype_default, "afp_openfork: ad_open: %s", strerror(errno) );
+ ret = AFPERR_PARAM;
+ goto openfork_err;
+ break;
}
- break;
- case EMFILE :
- case ENFILE :
- ret = AFPERR_NFILE;
- goto openfork_err;
- break;
- case EISDIR :
- ret = AFPERR_BADTYPE;
- goto openfork_err;
- break;
- default:
- LOG(log_error, logtype_default, "afp_openfork: ad_open: %s", strerror(errno) );
- ret = AFPERR_PARAM;
- goto openfork_err;
- break;
}
- }
- } else {
- /* try opening in read-only mode */
- upath = mtoupath(vol, path);
- ret = AFPERR_NOOBJ;
- if (ad_open(upath, adflags, O_RDONLY, 0, ofork->of_ad) < 0) {
- switch ( errno ) {
- case EROFS:
- ret = AFPERR_VLOCK;
- case EACCES:
- /* check for a read-only data fork */
- if ((adflags != ADFLAGS_HF) &&
- (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0))
- goto openfork_err;
+ } else {
+ /* try opening in read-only mode */
+ upath = mtoupath(vol, path);
+ ret = AFPERR_NOOBJ;
+ if (ad_open(upath, adflags, O_RDONLY, 0, ofork->of_ad) < 0) {
+ switch ( errno ) {
+ case EROFS:
+ ret = AFPERR_VLOCK;
+ case EACCES:
+ /* check for a read-only data fork */
+ if ((adflags != ADFLAGS_HF) &&
+ (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0))
+ goto openfork_err;
- adflags = ADFLAGS_DF;
- break;
- case ENOENT:
- {
- struct stat st;
+ adflags = ADFLAGS_DF;
+ break;
+ case ENOENT:
+ {
+ struct stat st;
+
+ /* see if client asked for the data fork */
+ if (fork == OPENFORK_DATA) {
+ if (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0) {
+ goto openfork_err;
+ }
+ adflags = ADFLAGS_DF;
- /* see if client asked for the data fork */
- if (fork == OPENFORK_DATA) {
- if (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0) {
+ } else if (stat(upath, &st) != 0) {
goto openfork_err;
}
- adflags = ADFLAGS_DF;
-
- } else if (stat(upath, &st) != 0) {
- goto openfork_err;
}
+ break;
+ case EMFILE :
+ case ENFILE :
+ ret = AFPERR_NFILE;
+ goto openfork_err;
+ break;
+ case EISDIR :
+ ret = AFPERR_BADTYPE;
+ goto openfork_err;
+ break;
+ default:
+ LOG(log_error, logtype_default, "afp_openfork: ad_open: %s", strerror(errno) );
+ goto openfork_err;
+ break;
}
- break;
- case EMFILE :
- case ENFILE :
- ret = AFPERR_NFILE;
- goto openfork_err;
- break;
- case EISDIR :
- ret = AFPERR_BADTYPE;
- goto openfork_err;
- break;
- default:
- LOG(log_error, logtype_default, "afp_openfork: ad_open: %s", strerror(errno) );
- goto openfork_err;
- break;
}
}
- }
- if ((adflags & ADFLAGS_HF) &&
- (ad_getoflags( ofork->of_ad, ADFLAGS_HF ) & O_CREAT)) {
- ad_setentrylen( ofork->of_ad, ADEID_NAME, strlen( path ));
- memcpy(ad_entry( ofork->of_ad, ADEID_NAME ), path,
- ad_getentrylen( ofork->of_ad, ADEID_NAME ));
- ad_flush( ofork->of_ad, adflags );
- }
+ if ((adflags & ADFLAGS_HF) &&
+ (ad_getoflags( ofork->of_ad, ADFLAGS_HF ) & O_CREAT)) {
+ ad_setentrylen( ofork->of_ad, ADEID_NAME, strlen( path ));
+ memcpy(ad_entry( ofork->of_ad, ADEID_NAME ), path,
+ ad_getentrylen( ofork->of_ad, ADEID_NAME ));
+ ad_flush( ofork->of_ad, adflags );
+ }
- if (( ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof( u_int16_t ),
- &buflen, attrbits )) != AFP_OK ) {
- ad_close( ofork->of_ad, adflags );
- goto openfork_err;
- }
+ if (( ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof( u_int16_t ),
+ &buflen, attrbits )) != AFP_OK ) {
+ ad_close( ofork->of_ad, adflags );
+ goto openfork_err;
+ }
- *rbuflen = buflen + 2 * sizeof( u_int16_t );
- bitmap = htons( bitmap );
- memcpy(rbuf, &bitmap, sizeof( u_int16_t ));
- rbuf += sizeof( u_int16_t );
-
- /*
- * synchronization locks:
- *
- * here's the ritual:
- * 1) attempt a read lock to see if we have read or write
- * privileges.
- * 2) if that succeeds, set a write lock to correspond to the
- * deny mode requested.
- * 3) whenever a file is read/written, locks get set which
- * prevent conflicts.
- */
+ *rbuflen = buflen + 2 * sizeof( u_int16_t );
+ bitmap = htons( bitmap );
+ memcpy(rbuf, &bitmap, sizeof( u_int16_t ));
+ rbuf += sizeof( u_int16_t );
- /* don't try to lock non-existent rforks. */
- if ((eid == ADEID_DFORK) || (ad_hfileno(ofork->of_ad) != -1)) {
+ /*
+ * synchronization locks:
+ *
+ * here's the ritual:
+ * 1) attempt a read lock to see if we have read or write
+ * privileges.
+ * 2) if that succeeds, set a write lock to correspond to the
+ * deny mode requested.
+ * 3) whenever a file is read/written, locks get set which
+ * prevent conflicts.
+ */
- /* try to see if we have access. */
- ret = 0;
- if (access & OPENACC_WR) {
- ofork->of_flags |= AFPFORK_ACCWR;
- ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK,
- AD_FILELOCK_WR, 1, ofrefnum);
- }
+ /* don't try to lock non-existent rforks. */
+ if ((eid == ADEID_DFORK) || (ad_hfileno(ofork->of_ad) != -1)) {
- if (!ret && (access & OPENACC_RD)) {
- ofork->of_flags |= AFPFORK_ACCRD;
- ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK,
- AD_FILELOCK_RD, 1, ofrefnum);
- }
+ /* try to see if we have access. */
+ ret = 0;
+ if (access & OPENACC_WR) {
+ ofork->of_flags |= AFPFORK_ACCWR;
+ ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK,
+ AD_FILELOCK_WR, 1, ofrefnum);
+ }
- /* can we access the fork? */
- if (ret < 0) {
- ad_close( ofork->of_ad, adflags );
- of_dealloc( ofork );
- ofrefnum = 0;
- memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
- return (AFPERR_DENYCONF);
- }
+ if (!ret && (access & OPENACC_RD)) {
+ ofork->of_flags |= AFPFORK_ACCRD;
+ ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK,
+ AD_FILELOCK_RD, 1, ofrefnum);
+ }
- /* now try to set the deny lock. if the fork is open for read or
- * write, a read lock will already have been set. otherwise, we upgrade
- * our lock to a write lock.
- *
- * NOTE: we can't write lock a read-only file. on those, we just
- * make sure that we have a read lock set. that way, we at least prevent
- * someone else from really setting a deny read/write on the file. */
- lockop = (ad_getoflags(ofork->of_ad, eid) & O_RDWR) ?
- ADLOCK_WR : ADLOCK_RD;
- ret = (access & OPENACC_DWR) ? ad_lock(ofork->of_ad, eid,
- lockop | ADLOCK_FILELOCK |
- ADLOCK_UPGRADE, AD_FILELOCK_WR, 1,
- ofrefnum) : 0;
- if (!ret && (access & OPENACC_DRD))
- ret = ad_lock(ofork->of_ad, eid, lockop | ADLOCK_FILELOCK |
- ADLOCK_UPGRADE, AD_FILELOCK_RD, 1, ofrefnum);
-
- if (ret < 0) {
- ret = errno;
- ad_close( ofork->of_ad, adflags );
- of_dealloc( ofork );
- switch (ret) {
- case EAGAIN: /* return data anyway */
- case EACCES:
- case EINVAL:
+ /* can we access the fork? */
+ if (ret < 0) {
+ ad_close( ofork->of_ad, adflags );
+ of_dealloc( ofork );
ofrefnum = 0;
memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
- return( AFPERR_DENYCONF );
- break;
- default:
- *rbuflen = 0;
- LOG(log_error, logtype_default, "afp_openfork: ad_lock: %s", strerror(errno) );
- return( AFPERR_PARAM );
+ return (AFPERR_DENYCONF);
+ }
+
+ /* now try to set the deny lock. if the fork is open for read or
+ * write, a read lock will already have been set. otherwise, we upgrade
+ * our lock to a write lock.
+ *
+ * NOTE: we can't write lock a read-only file. on those, we just
+ * make sure that we have a read lock set. that way, we at least prevent
+ * someone else from really setting a deny read/write on the file. */
+ lockop = (ad_getoflags(ofork->of_ad, eid) & O_RDWR) ?
+ ADLOCK_WR : ADLOCK_RD;
+ ret = (access & OPENACC_DWR) ? ad_lock(ofork->of_ad, eid,
+ lockop | ADLOCK_FILELOCK |
+ ADLOCK_UPGRADE, AD_FILELOCK_WR, 1,
+ ofrefnum) : 0;
+ if (!ret && (access & OPENACC_DRD))
+ ret = ad_lock(ofork->of_ad, eid, lockop | ADLOCK_FILELOCK |
+ ADLOCK_UPGRADE, AD_FILELOCK_RD, 1, ofrefnum);
+
+ if (ret < 0) {
+ ret = errno;
+ ad_close( ofork->of_ad, adflags );
+ of_dealloc( ofork );
+ switch (ret) {
+ case EAGAIN: /* return data anyway */
+ case EACCES:
+ case EINVAL:
+ ofrefnum = 0;
+ memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
+ return( AFPERR_DENYCONF );
+ break;
+ default:
+ *rbuflen = 0;
+ LOG(log_error, logtype_default, "afp_openfork: ad_lock: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
}
}
- }
- memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
- return( AFP_OK );
+ memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
+ return( AFP_OK );
openfork_err:
- of_dealloc( ofork );
- if (errno == EACCES)
- return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS;
- return ret;
-}
-
-int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- int32_t size;
- u_int16_t ofrefnum, bitmap;
- int err;
-
- ibuf += 2;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- ibuf += sizeof( ofrefnum );
- memcpy(&bitmap, ibuf, sizeof(bitmap));
- bitmap = ntohs(bitmap);
- ibuf += sizeof( bitmap );
- memcpy(&size, ibuf, sizeof( size ));
- size = ntohl( size );
-
- *rbuflen = 0;
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_setforkparams: of_find: %s", strerror(errno) );
- return( AFPERR_PARAM );
+ of_dealloc( ofork );
+ if (errno == EACCES)
+ return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS;
+ return ret;
}
- if (ofork->of_vol->v_flags & AFPVOL_RO)
- return AFPERR_VLOCK;
+ int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ int32_t size;
+ u_int16_t ofrefnum, bitmap;
+ int err;
+
+ ibuf += 2;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ ibuf += sizeof( ofrefnum );
+ memcpy(&bitmap, ibuf, sizeof(bitmap));
+ bitmap = ntohs(bitmap);
+ ibuf += sizeof( bitmap );
+ memcpy(&size, ibuf, sizeof( size ));
+ size = ntohl( size );
- if ((ofork->of_flags & AFPFORK_ACCWR) == 0)
- return AFPERR_ACCESS;
+ *rbuflen = 0;
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_setforkparams: of_find: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
- if (size < 0)
- return AFPERR_PARAM;
+ if (ofork->of_vol->v_flags & AFPVOL_RO)
+ return AFPERR_VLOCK;
- if ((bitmap == (1<<FILPBIT_DFLEN)) && (ofork->of_flags & AFPFORK_DATA)) {
- err = ad_dtruncate( ofork->of_ad, size );
- if (err < 0)
- goto afp_setfork_err;
- } else if ((bitmap == (1<<FILPBIT_RFLEN)) &&
- (ofork->of_flags & AFPFORK_RSRC)) {
- ad_refresh( ofork->of_ad );
- err = ad_rtruncate(ofork->of_ad, size);
- if (err < 0)
- goto afp_setfork_err;
+ if ((ofork->of_flags & AFPFORK_ACCWR) == 0)
+ return AFPERR_ACCESS;
- if (ad_flush( ofork->of_ad, ADFLAGS_HF ) < 0) {
- LOG(log_error, logtype_default, "afp_setforkparams: ad_flush: %s",
+ if (size < 0)
+ return AFPERR_PARAM;
+
+ if ((bitmap == (1<<FILPBIT_DFLEN)) && (ofork->of_flags & AFPFORK_DATA)) {
+ err = ad_dtruncate( ofork->of_ad, size );
+ if (err < 0)
+ goto afp_setfork_err;
+ } else if ((bitmap == (1<<FILPBIT_RFLEN)) &&
+ (ofork->of_flags & AFPFORK_RSRC)) {
+ ad_refresh( ofork->of_ad );
+ err = ad_rtruncate(ofork->of_ad, size);
+ if (err < 0)
+ goto afp_setfork_err;
+
+ if (ad_flush( ofork->of_ad, ADFLAGS_HF ) < 0) {
+ LOG(log_error, logtype_default, "afp_setforkparams: ad_flush: %s",
strerror(errno) );
- return( AFPERR_PARAM );
- }
- } else
- return AFPERR_BITMAP;
+ return( AFPERR_PARAM );
+ }
+ } else
+ return AFPERR_BITMAP;
#ifdef AFS
- if ( flushfork( ofork ) < 0 ) {
- LOG(log_error, logtype_default, "afp_setforkparams: flushfork: %s", strerror(errno) );
- }
+ if ( flushfork( ofork ) < 0 ) {
+ LOG(log_error, logtype_default, "afp_setforkparams: flushfork: %s", strerror(errno) );
+ }
#endif /* AFS */
- return( AFP_OK );
+ return( AFP_OK );
afp_setfork_err:
- if (err == -2)
- return AFPERR_LOCK;
- else {
- switch (errno) {
- case EROFS:
- return AFPERR_VLOCK;
- case EPERM:
- case EACCES:
- return AFPERR_ACCESS;
- case EDQUOT:
- case EFBIG:
- case ENOSPC:
- return AFPERR_DFULL;
- default:
- return AFPERR_PARAM;
+ if (err == -2)
+ return AFPERR_LOCK;
+ else {
+ switch (errno) {
+ case EROFS:
+ return AFPERR_VLOCK;
+ case EPERM:
+ case EACCES:
+ return AFPERR_ACCESS;
+ case EDQUOT:
+ case EFBIG:
+ case ENOSPC:
+ return AFPERR_DFULL;
+ default:
+ return AFPERR_PARAM;
+ }
}
}
-}
-/* for this to work correctly, we need to check for locks before each
- * read and write. that's most easily handled by always doing an
- * appropriate check before each ad_read/ad_write. other things
- * that can change files like truncate are handled internally to those
- * functions.
- */
+ /* for this to work correctly, we need to check for locks before each
+ * read and write. that's most easily handled by always doing an
+ * appropriate check before each ad_read/ad_write. other things
+ * that can change files like truncate are handled internally to those
+ * functions.
+ */
#define ENDBIT(a) ((a) & 0x80)
#define UNLOCKBIT(a) ((a) & 0x01)
-int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- int32_t offset, length;
- int eid;
- u_int16_t ofrefnum;
- u_int8_t flags;
-
- *rbuflen = 0;
-
- /* figure out parameters */
- ibuf++;
- flags = *ibuf; /* first bit = endflag, lastbit = lockflag */
- ibuf++;
- memcpy(&ofrefnum, ibuf, sizeof(ofrefnum));
- ibuf += sizeof(ofrefnum);
-
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_bytelock: of_find: %s", strerror(errno) );
- return( AFPERR_PARAM );
- }
+ int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ int32_t offset, length;
+ int eid;
+ u_int16_t ofrefnum;
+ u_int8_t flags;
- if ( ofork->of_flags & AFPFORK_DATA) {
- eid = ADEID_DFORK;
- } else if (ofork->of_flags & AFPFORK_RSRC) {
- eid = ADEID_RFORK;
- } else
- return AFPERR_PARAM;
-
- memcpy(&offset, ibuf, sizeof( offset ));
- offset = ntohl(offset);
- ibuf += sizeof(offset);
-
- memcpy(&length, ibuf, sizeof( length ));
- length = ntohl(length);
- if (length == 0xFFFFFFFF)
- length = BYTELOCK_MAX;
- else if (length <= 0) {
- return AFPERR_PARAM;
- } else if ((length >= AD_FILELOCK_BASE) &&
- (ad_hfileno(ofork->of_ad) == -1))
- return AFPERR_LOCK;
-
- if (ENDBIT(flags))
- offset += ad_size(ofork->of_ad, eid);
-
- if (offset < 0) /* error if we have a negative offset */
- return AFPERR_PARAM;
-
- /* if the file is a read-only file, we use read locks instead of
- * write locks. that way, we can prevent anyone from initiating
- * a write lock. */
- if (ad_lock(ofork->of_ad, eid, UNLOCKBIT(flags) ? ADLOCK_CLR :
- ((ad_getoflags(ofork->of_ad, eid) & O_RDWR) ?
- ADLOCK_WR : ADLOCK_RD), offset, length,
- ofork->of_refnum) < 0) {
- switch (errno) {
- case EACCES:
- case EAGAIN:
- return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_LOCK;
- break;
- case ENOLCK:
- return AFPERR_NLOCK;
- break;
- case EINVAL:
- return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_RANGEOVR;
- break;
- case EBADF:
- default:
+ *rbuflen = 0;
+
+ /* figure out parameters */
+ ibuf++;
+ flags = *ibuf; /* first bit = endflag, lastbit = lockflag */
+ ibuf++;
+ memcpy(&ofrefnum, ibuf, sizeof(ofrefnum));
+ ibuf += sizeof(ofrefnum);
+
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_bytelock: of_find: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
+
+ if ( ofork->of_flags & AFPFORK_DATA) {
+ eid = ADEID_DFORK;
+ } else if (ofork->of_flags & AFPFORK_RSRC) {
+ eid = ADEID_RFORK;
+ } else
return AFPERR_PARAM;
- break;
+
+ memcpy(&offset, ibuf, sizeof( offset ));
+ offset = ntohl(offset);
+ ibuf += sizeof(offset);
+
+ memcpy(&length, ibuf, sizeof( length ));
+ length = ntohl(length);
+ if (length == 0xFFFFFFFF)
+ length = BYTELOCK_MAX;
+ else if (length <= 0) {
+ return AFPERR_PARAM;
+ } else if ((length >= AD_FILELOCK_BASE) &&
+ (ad_hfileno(ofork->of_ad) == -1))
+ return AFPERR_LOCK;
+
+ if (ENDBIT(flags))
+ offset += ad_size(ofork->of_ad, eid);
+
+ if (offset < 0) /* error if we have a negative offset */
+ return AFPERR_PARAM;
+
+ /* if the file is a read-only file, we use read locks instead of
+ * write locks. that way, we can prevent anyone from initiating
+ * a write lock. */
+ if (ad_lock(ofork->of_ad, eid, UNLOCKBIT(flags) ? ADLOCK_CLR :
+ ((ad_getoflags(ofork->of_ad, eid) & O_RDWR) ?
+ ADLOCK_WR : ADLOCK_RD), offset, length,
+ ofork->of_refnum) < 0) {
+ switch (errno) {
+ case EACCES:
+ case EAGAIN:
+ return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_LOCK;
+ break;
+ case ENOLCK:
+ return AFPERR_NLOCK;
+ break;
+ case EINVAL:
+ return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_RANGEOVR;
+ break;
+ case EBADF:
+ default:
+ return AFPERR_PARAM;
+ break;
+ }
}
- }
- offset = htonl(offset);
- memcpy(rbuf, &offset, sizeof( offset ));
- *rbuflen = sizeof( offset );
- return( AFP_OK );
-}
+ offset = htonl(offset);
+ memcpy(rbuf, &offset, sizeof( offset ));
+ *rbuflen = sizeof( offset );
+ return( AFP_OK );
+ }
#undef UNLOCKBIT
-static __inline__ int crlf( of )
-struct ofork *of;
-{
- struct extmap *em;
+ static __inline__ int crlf( of )
+ struct ofork *of;
+ {
+ struct extmap *em;
- 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 ||
- memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) {
- return( 1 );
- } else {
- return( 0 );
- }
- } else {
- if ( memcmp( ufinderi,
- ad_entry( of->of_ad, ADEID_FINDERI ), 4 ) == 0 ) {
- return( 1 );
+ 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 ||
+ memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) {
+ return( 1 );
+ } else {
+ return( 0 );
+ }
} else {
- return( 0 );
+ if ( memcmp( ufinderi,
+ ad_entry( of->of_ad, ADEID_FINDERI ), 4 ) == 0 ) {
+ return( 1 );
+ } else {
+ return( 0 );
+ }
}
}
-}
-
-static __inline__ ssize_t read_file(struct ofork *ofork, int eid,
- int offset, u_char nlmask,
- u_char nlchar, char *rbuf,
- int *rbuflen, const int xlate)
-{
- ssize_t cc;
- int eof = 0;
- char *p, *q;
- cc = ad_read(ofork->of_ad, eid, offset, rbuf, *rbuflen);
- if ( cc < 0 ) {
- LOG(log_error, logtype_default, "afp_read: ad_read: %s", strerror(errno) );
- *rbuflen = 0;
- return( AFPERR_PARAM );
- }
- if ( cc < *rbuflen ) {
- eof = 1;
- }
+ static __inline__ ssize_t read_file(struct ofork *ofork, int eid,
+ int offset, u_char nlmask,
+ u_char nlchar, char *rbuf,
+ int *rbuflen, const int xlate)
+ {
+ ssize_t cc;
+ int eof = 0;
+ char *p, *q;
- /*
- * Do Newline check.
- */
- if ( nlmask != 0 ) {
- for ( p = rbuf, q = p + cc; p < q; ) {
- if (( *p++ & nlmask ) == nlchar ) {
- break;
- }
+ cc = ad_read(ofork->of_ad, eid, offset, rbuf, *rbuflen);
+ if ( cc < 0 ) {
+ LOG(log_error, logtype_default, "afp_read: ad_read: %s", strerror(errno) );
+ *rbuflen = 0;
+ return( AFPERR_PARAM );
}
- if ( p != q ) {
- cc = p - rbuf;
- eof = 0;
+ if ( cc < *rbuflen ) {
+ eof = 1;
}
- }
- /*
- * If this file is of type TEXT, then swap \012 to \015.
- */
- if (xlate) {
- for ( p = rbuf, q = p + cc; p < q; p++ ) {
- if ( *p == '\012' ) {
- *p = '\015';
- } else if ( *p == '\015' ) {
- *p = '\012';
+ /*
+ * Do Newline check.
+ */
+ if ( nlmask != 0 ) {
+ for ( p = rbuf, q = p + cc; p < q; ) {
+ if (( *p++ & nlmask ) == nlchar ) {
+ break;
+ }
+ }
+ if ( p != q ) {
+ cc = p - rbuf;
+ eof = 0;
}
-
}
- }
- *rbuflen = cc;
- if ( eof ) {
- return( AFPERR_EOF );
- }
- return AFP_OK;
-}
+ /*
+ * If this file is of type TEXT, then swap \012 to \015.
+ */
+ if (xlate) {
+ for ( p = rbuf, q = p + cc; p < q; p++ ) {
+ if ( *p == '\012' ) {
+ *p = '\015';
+ } else if ( *p == '\015' ) {
+ *p = '\012';
+ }
-int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen)
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- off_t size;
- int32_t offset, saveoff, reqcount;
- int cc, err, eid, xlate = 0;
- u_int16_t ofrefnum;
- u_char nlmask, nlchar;
-
- ibuf += 2;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- ibuf += sizeof( u_short );
-
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_read: of_find: %s", strerror(errno) );
- err = AFPERR_PARAM;
- goto afp_read_err;
- }
+ }
+ }
- if ((ofork->of_flags & AFPFORK_ACCRD) == 0) {
- err = AFPERR_ACCESS;
- goto afp_read_err;
+ *rbuflen = cc;
+ if ( eof ) {
+ return( AFPERR_EOF );
+ }
+ return AFP_OK;
}
- memcpy(&offset, ibuf, sizeof( offset ));
- offset = ntohl( offset );
- ibuf += sizeof( offset );
- memcpy(&reqcount, ibuf, sizeof( reqcount ));
- reqcount = ntohl( reqcount );
- ibuf += sizeof( reqcount );
+ int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen)
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ off_t size;
+ int32_t offset, saveoff, reqcount;
+ int cc, err, eid, xlate = 0;
+ u_int16_t ofrefnum;
+ u_char nlmask, nlchar;
+
+ ibuf += 2;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ ibuf += sizeof( u_short );
+
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_read: of_find: %s", strerror(errno) );
+ err = AFPERR_PARAM;
+ goto afp_read_err;
+ }
- nlmask = *ibuf++;
- nlchar = *ibuf++;
+ if ((ofork->of_flags & AFPFORK_ACCRD) == 0) {
+ err = AFPERR_ACCESS;
+ goto afp_read_err;
+ }
- /* if we wanted to be picky, we could add in the following
- * bit: if (afp_version == 11 && !(nlmask == 0xFF || !nlmask))
- */
- if (reqcount < 0 || offset < 0) {
- err = AFPERR_PARAM;
- goto afp_read_err;
- }
+ memcpy(&offset, ibuf, sizeof( offset ));
+ offset = ntohl( offset );
+ ibuf += sizeof( offset );
+ memcpy(&reqcount, ibuf, sizeof( reqcount ));
+ reqcount = ntohl( reqcount );
+ ibuf += sizeof( reqcount );
- if ( ofork->of_flags & AFPFORK_DATA) {
- eid = ADEID_DFORK;
- xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0;
- } else if (ofork->of_flags & AFPFORK_RSRC) {
- eid = ADEID_RFORK;
- } else { /* fork wasn't opened. this should never really happen. */
- err = AFPERR_ACCESS;
- goto afp_read_err;
- }
+ nlmask = *ibuf++;
+ nlchar = *ibuf++;
- /* zero request count */
- if (!reqcount) {
- err = AFP_OK;
- goto afp_read_err;
- }
+ /* if we wanted to be picky, we could add in the following
+ * bit: if (afp_version == 11 && !(nlmask == 0xFF || !nlmask))
+ */
+ if (reqcount < 0 || offset < 0) {
+ err = AFPERR_PARAM;
+ goto afp_read_err;
+ }
- /* reqcount isn't always truthful. we need to deal with that. */
- if ((size = ad_size(ofork->of_ad, eid)) == 0) {
- err = AFPERR_EOF;
- goto afp_read_err;
- }
+ if ( ofork->of_flags & AFPFORK_DATA) {
+ eid = ADEID_DFORK;
+ xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0;
+ } else if (ofork->of_flags & AFPFORK_RSRC) {
+ eid = ADEID_RFORK;
+ } else { /* fork wasn't opened. this should never really happen. */
+ err = AFPERR_ACCESS;
+ goto afp_read_err;
+ }
- saveoff = offset;
- if (ad_tmplock(ofork->of_ad, eid, ADLOCK_RD, saveoff, reqcount) < 0) {
- err = AFPERR_LOCK;
- goto afp_read_err;
- }
+ /* zero request count */
+ if (!reqcount) {
+ err = AFP_OK;
+ goto afp_read_err;
+ }
-#define min(a,b) ((a)<(b)?(a):(b))
- *rbuflen = min( reqcount, *rbuflen );
- err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen,
- xlate);
- if (err < 0)
- goto afp_read_done;
-
- /* dsi can stream requests. we can only do this if we're not checking
- * for an end-of-line character. oh well. */
- if ((obj->proto == AFPPROTO_DSI) && (*rbuflen < reqcount) && !nlmask) {
- DSI *dsi = obj->handle;
-
- /* subtract off the offset */
- size -= offset;
- if (reqcount > size) {
- reqcount = size;
+ /* reqcount isn't always truthful. we need to deal with that. */
+ if ((size = ad_size(ofork->of_ad, eid)) == 0) {
err = AFPERR_EOF;
+ goto afp_read_err;
}
- if (obj->options.flags & OPTION_DEBUG) {
- printf( "(read) reply: %d/%d, %d\n", *rbuflen,
- reqcount, dsi->clientID);
- bprint(rbuf, *rbuflen);
+ saveoff = offset;
+ if (ad_tmplock(ofork->of_ad, eid, ADLOCK_RD, saveoff, reqcount) < 0) {
+ err = AFPERR_LOCK;
+ goto afp_read_err;
}
- offset += *rbuflen;
+#define min(a,b) ((a)<(b)?(a):(b))
+ *rbuflen = min( reqcount, *rbuflen );
+ err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen,
+ xlate);
+ if (err < 0)
+ goto afp_read_done;
- /* dsi_readinit() returns size of next read buffer. by this point,
- * we know that we're sending some data. if we fail, something
- * horrible happened. */
- if ((*rbuflen = dsi_readinit(dsi, rbuf, *rbuflen, reqcount, err)) < 0)
- goto afp_read_exit;
+ /* dsi can stream requests. we can only do this if we're not checking
+ * for an end-of-line character. oh well. */
+ if ((obj->proto == AFPPROTO_DSI) && (*rbuflen < reqcount) && !nlmask) {
+ DSI *dsi = obj->handle;
- /* due to the nature of afp packets, we have to exit if we get
- an error. we can't do this with translation on. */
+ /* subtract off the offset */
+ size -= offset;
+ if (reqcount > size) {
+ reqcount = size;
+ err = AFPERR_EOF;
+ }
+
+ if (obj->options.flags & OPTION_DEBUG) {
+ printf( "(read) reply: %d/%d, %d\n", *rbuflen,
+ reqcount, dsi->clientID);
+ bprint(rbuf, *rbuflen);
+ }
+
+ offset += *rbuflen;
+
+ /* dsi_readinit() returns size of next read buffer. by this point,
+ * we know that we're sending some data. if we fail, something
+ * horrible happened. */
+ if ((*rbuflen = dsi_readinit(dsi, rbuf, *rbuflen, reqcount, err)) < 0)
+ goto afp_read_exit;
+
+ /* due to the nature of afp packets, we have to exit if we get
+ an error. we can't do this with translation on. */
#ifdef HAVE_SENDFILE_READ
- if (!(xlate || (obj->options.flags & OPTION_DEBUG))) {
- if (ad_readfile(ofork->of_ad, eid, dsi->socket, offset,
- dsi->datasize) < 0) {
- if (errno == EINVAL)
- goto afp_read_loop;
- else {
- LOG(log_error, logtype_default, "afp_read: ad_readfile: %s", strerror(errno));
- goto afp_read_exit;
+ if (!(xlate || (obj->options.flags & OPTION_DEBUG))) {
+ if (ad_readfile(ofork->of_ad, eid, dsi->socket, offset,
+ dsi->datasize) < 0) {
+ if (errno == EINVAL)
+ goto afp_read_loop;
+ else {
+ LOG(log_error, logtype_default, "afp_read: ad_readfile: %s", strerror(errno));
+ goto afp_read_exit;
+ }
}
- }
- dsi_readdone(dsi);
- goto afp_read_done;
- }
+ dsi_readdone(dsi);
+ goto afp_read_done;
+ }
afp_read_loop:
#endif /* HAVE_SENDFILE_READ */
- /* fill up our buffer. */
- while (*rbuflen > 0) {
- cc = read_file(ofork, eid, offset, nlmask, nlchar, rbuf,
- rbuflen, xlate);
- if (cc < 0)
- goto afp_read_exit;
+ /* fill up our buffer. */
+ while (*rbuflen > 0) {
+ cc = read_file(ofork, eid, offset, nlmask, nlchar, rbuf,
+ rbuflen, xlate);
+ if (cc < 0)
+ goto afp_read_exit;
- offset += *rbuflen;
- if (obj->options.flags & OPTION_DEBUG) {
- printf( "(read) reply: %d, %d\n", *rbuflen, dsi->clientID);
- bprint(rbuf, *rbuflen);
+ offset += *rbuflen;
+ if (obj->options.flags & OPTION_DEBUG) {
+ printf( "(read) reply: %d, %d\n", *rbuflen, dsi->clientID);
+ bprint(rbuf, *rbuflen);
+ }
+
+ /* dsi_read() also returns buffer size of next allocation */
+ cc = dsi_read(dsi, rbuf, *rbuflen); /* send it off */
+ if (cc < 0)
+ goto afp_read_exit;
+ *rbuflen = cc;
}
+ dsi_readdone(dsi);
+ goto afp_read_done;
- /* dsi_read() also returns buffer size of next allocation */
- cc = dsi_read(dsi, rbuf, *rbuflen); /* send it off */
- if (cc < 0)
- goto afp_read_exit;
- *rbuflen = cc;
+afp_read_exit:
+ LOG(log_error, logtype_default, "afp_read: %s", strerror(errno));
+ dsi_readdone(dsi);
+ ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
+ obj->exit(1);
}
- dsi_readdone(dsi);
- goto afp_read_done;
-afp_read_exit:
- LOG(log_error, logtype_default, "afp_read: %s", strerror(errno));
- dsi_readdone(dsi);
+afp_read_done:
ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
- obj->exit(1);
+ return err;
+
+afp_read_err:
+ *rbuflen = 0;
+ return err;
}
-afp_read_done:
- ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
- return err;
+ int afp_flush(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct vol *vol;
+ u_int16_t vid;
-afp_read_err:
- *rbuflen = 0;
- return err;
-}
-
-int afp_flush(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct vol *vol;
- u_int16_t vid;
+ *rbuflen = 0;
+ ibuf += 2;
- *rbuflen = 0;
- ibuf += 2;
+ memcpy(&vid, ibuf, sizeof(vid));
+ if (( vol = getvolbyvid( vid )) == NULL ) {
+ return( AFPERR_PARAM );
+ }
- memcpy(&vid, ibuf, sizeof(vid));
- if (( vol = getvolbyvid( vid )) == NULL ) {
- return( AFPERR_PARAM );
+ of_flush(vol);
+ return( AFP_OK );
}
- of_flush(vol);
- return( AFP_OK );
-}
+ int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ u_int16_t ofrefnum;
-int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- u_int16_t ofrefnum;
+ *rbuflen = 0;
+ ibuf += 2;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- *rbuflen = 0;
- ibuf += 2;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_flushfork: of_find: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_flushfork: of_find: %s", strerror(errno) );
- return( AFPERR_PARAM );
- }
+ if ( flushfork( ofork ) < 0 ) {
+ LOG(log_error, logtype_default, "afp_flushfork: %s", strerror(errno) );
+ }
- if ( flushfork( ofork ) < 0 ) {
- LOG(log_error, logtype_default, "afp_flushfork: %s", strerror(errno) );
+ return( AFP_OK );
}
- return( AFP_OK );
-}
-
-/* this is very similar to closefork */
-int flushfork( ofork )
-struct ofork *ofork;
-{
- struct timeval tv;
- int len, err = 0, doflush = 0;
+ /* this is very similar to closefork */
+ int flushfork( ofork )
+ struct ofork *ofork;
+ {
+ struct timeval tv;
+ int len, err = 0, doflush = 0;
- if ( ad_dfileno( ofork->of_ad ) != -1 &&
- fsync( ad_dfileno( ofork->of_ad )) < 0 ) {
- LOG(log_error, logtype_default, "flushfork: dfile(%d) %s",
+ if ( ad_dfileno( ofork->of_ad ) != -1 &&
+ fsync( ad_dfileno( ofork->of_ad )) < 0 ) {
+ LOG(log_error, logtype_default, "flushfork: dfile(%d) %s",
ad_dfileno(ofork->of_ad), strerror(errno) );
- err = -1;
- }
+ err = -1;
+ }
- if ( ad_hfileno( ofork->of_ad ) != -1 ) {
+ if ( ad_hfileno( ofork->of_ad ) != -1 ) {
- /* read in the rfork length */
- len = ad_getentrylen(ofork->of_ad, ADEID_RFORK);
- ad_refresh(ofork->of_ad);
+ /* read in the rfork length */
+ len = ad_getentrylen(ofork->of_ad, ADEID_RFORK);
+ ad_refresh(ofork->of_ad);
- /* set the date if we're dirty */
- if ((ofork->of_flags & AFPFORK_DIRTY) &&
- (gettimeofday(&tv, NULL) == 0)) {
- ad_setdate(ofork->of_ad, AD_DATE_MODIFY|AD_DATE_UNIX, tv.tv_sec);
- ofork->of_flags &= ~AFPFORK_DIRTY;
- doflush++;
- }
+ /* set the date if we're dirty */
+ if ((ofork->of_flags & AFPFORK_DIRTY) &&
+ (gettimeofday(&tv, NULL) == 0)) {
+ ad_setdate(ofork->of_ad, AD_DATE_MODIFY|AD_DATE_UNIX, tv.tv_sec);
+ ofork->of_flags &= ~AFPFORK_DIRTY;
+ doflush++;
+ }
- /* if we're actually flushing this fork, make sure to set the
- * length. otherwise, just use the stored length */
- if ((ofork->of_flags & AFPFORK_RSRC) &&
- (len != ad_getentrylen(ofork->of_ad, ADEID_RFORK))) {
- ad_setentrylen(ofork->of_ad, ADEID_RFORK, len);
- doflush++;
- }
+ /* if we're actually flushing this fork, make sure to set the
+ * length. otherwise, just use the stored length */
+ if ((ofork->of_flags & AFPFORK_RSRC) &&
+ (len != ad_getentrylen(ofork->of_ad, ADEID_RFORK))) {
+ ad_setentrylen(ofork->of_ad, ADEID_RFORK, len);
+ doflush++;
+ }
- /* flush the header (if it is a resource fork) */
- if (ofork->of_flags & AFPFORK_RSRC)
- if (doflush && (ad_flush(ofork->of_ad, ADFLAGS_HF) < 0))
- err = -1;
+ /* flush the header (if it is a resource fork) */
+ if (ofork->of_flags & AFPFORK_RSRC)
+ if (doflush && (ad_flush(ofork->of_ad, ADFLAGS_HF) < 0))
+ err = -1;
- if (fsync( ad_hfileno( ofork->of_ad )) < 0)
- err = -1;
+ if (fsync( ad_hfileno( ofork->of_ad )) < 0)
+ err = -1;
- if (err < 0)
- LOG(log_error, logtype_default, "flushfork: hfile(%d) %s",
+ if (err < 0)
+ LOG(log_error, logtype_default, "flushfork: hfile(%d) %s",
ad_hfileno(ofork->of_ad), strerror(errno) );
+ }
+
+ return( err );
}
- return( err );
-}
+ int afp_closefork(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ struct timeval tv;
+ int adflags, aint, doflush = 0;
+ u_int16_t ofrefnum;
-int afp_closefork(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- struct timeval tv;
- int adflags, aint, doflush = 0;
- u_int16_t ofrefnum;
+ *rbuflen = 0;
+ ibuf += 2;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- *rbuflen = 0;
- ibuf += 2;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_closefork: of_find: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_closefork: of_find: %s", strerror(errno) );
- return( AFPERR_PARAM );
- }
+ adflags = 0;
+ if ((ofork->of_flags & AFPFORK_DATA) &&
+ (ad_dfileno( ofork->of_ad ) != -1)) {
+ adflags |= ADFLAGS_DF;
+ }
- adflags = 0;
- 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;
- if ( ad_hfileno( ofork->of_ad ) != -1 ) {
- adflags |= ADFLAGS_HF;
+ aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK );
+ ad_refresh( ofork->of_ad );
+ if ((ofork->of_flags & AFPFORK_DIRTY) &&
+ (gettimeofday(&tv, NULL) == 0)) {
+ ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,
+ tv.tv_sec);
+ doflush++;
+ }
- aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK );
- ad_refresh( ofork->of_ad );
- if ((ofork->of_flags & AFPFORK_DIRTY) &&
- (gettimeofday(&tv, NULL) == 0)) {
- ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,
- tv.tv_sec);
- doflush++;
+ /*
+ * Only set the rfork's length if we're closing the rfork.
+ */
+ if ((ofork->of_flags & AFPFORK_RSRC) && aint !=
+ ad_getentrylen( ofork->of_ad, ADEID_RFORK )) {
+ ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint );
+ doflush++;
+ }
+ if ( doflush ) {
+ ad_flush( ofork->of_ad, adflags );
+ }
}
- /*
- * Only set the rfork's length if we're closing the rfork.
- */
- if ((ofork->of_flags & AFPFORK_RSRC) && aint !=
- ad_getentrylen( ofork->of_ad, ADEID_RFORK )) {
- ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint );
- doflush++;
- }
- if ( doflush ) {
- ad_flush( ofork->of_ad, adflags );
+ if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
+ LOG(log_error, logtype_default, "afp_closefork: ad_close: %s", strerror(errno) );
+ return( AFPERR_PARAM );
}
- }
- if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
- LOG(log_error, logtype_default, "afp_closefork: ad_close: %s", strerror(errno) );
- return( AFPERR_PARAM );
+ of_dealloc( ofork );
+ return( AFP_OK );
}
- of_dealloc( ofork );
- return( AFP_OK );
-}
-
-static __inline__ ssize_t write_file(struct ofork *ofork, int eid,
- off_t offset, char *rbuf,
- size_t rbuflen, const int xlate)
-{
- char *p, *q;
- ssize_t cc;
+ static __inline__ ssize_t write_file(struct ofork *ofork, int eid,
+ off_t offset, char *rbuf,
+ size_t rbuflen, const int xlate)
+ {
+ char *p, *q;
+ ssize_t cc;
- /*
- * If this file is of type TEXT, swap \015 to \012.
- */
- if (xlate) {
- for ( p = rbuf, q = p + rbuflen; p < q; p++ ) {
- if ( *p == '\015' ) {
- *p = '\012';
- } else if ( *p == '\012' ) {
- *p = '\015';
+ /*
+ * If this file is of type TEXT, swap \015 to \012.
+ */
+ if (xlate) {
+ for ( p = rbuf, q = p + rbuflen; p < q; p++ ) {
+ if ( *p == '\015' ) {
+ *p = '\012';
+ } else if ( *p == '\012' ) {
+ *p = '\015';
+ }
}
}
- }
- if (( cc = ad_write(ofork->of_ad, eid, offset, 0,
- rbuf, rbuflen)) < 0 ) {
- switch ( errno ) {
- case EDQUOT :
- case EFBIG :
- case ENOSPC :
- return( AFPERR_DFULL );
- default :
- LOG(log_error, logtype_default, "afp_write: ad_write: %s", strerror(errno) );
- return( AFPERR_PARAM );
+ if (( cc = ad_write(ofork->of_ad, eid, offset, 0,
+ rbuf, rbuflen)) < 0 ) {
+ switch ( errno ) {
+ case EDQUOT :
+ case EFBIG :
+ case ENOSPC :
+ return( AFPERR_DFULL );
+ default :
+ LOG(log_error, logtype_default, "afp_write: ad_write: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
}
- }
-
- return cc;
-}
-/* FPWrite. NOTE: on an error, we always use afp_write_err as
- * the client may have sent us a bunch of data that's not reflected
- * in reqcount et al. */
-int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen)
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- int32_t offset, saveoff, reqcount;
- int endflag, eid, xlate = 0, err = AFP_OK;
- u_int16_t ofrefnum;
- ssize_t cc;
-
- /* figure out parameters */
- ibuf++;
- endflag = ENDBIT(*ibuf);
- ibuf++;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- ibuf += sizeof( ofrefnum );
- memcpy(&offset, ibuf, sizeof( offset ));
- offset = ntohl( offset );
- ibuf += sizeof( offset );
- memcpy(&reqcount, ibuf, sizeof( reqcount ));
- reqcount = ntohl( reqcount );
- ibuf += sizeof( reqcount );
-
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_write: of_find: %s", strerror(errno) );
- err = AFPERR_PARAM;
- goto afp_write_err;
+ return cc;
}
- if ((ofork->of_flags & AFPFORK_ACCWR) == 0) {
- err = AFPERR_ACCESS;
- goto afp_write_err;
- }
+ /* FPWrite. NOTE: on an error, we always use afp_write_err as
+ * the client may have sent us a bunch of data that's not reflected
+ * in reqcount et al. */
+ int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen)
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ int32_t offset, saveoff, reqcount;
+ int endflag, eid, xlate = 0, err = AFP_OK;
+ u_int16_t ofrefnum;
+ ssize_t cc;
+
+ /* figure out parameters */
+ ibuf++;
+ endflag = ENDBIT(*ibuf);
+ ibuf++;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ ibuf += sizeof( ofrefnum );
+ memcpy(&offset, ibuf, sizeof( offset ));
+ offset = ntohl( offset );
+ ibuf += sizeof( offset );
+ memcpy(&reqcount, ibuf, sizeof( reqcount ));
+ reqcount = ntohl( reqcount );
+ ibuf += sizeof( reqcount );
+
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_write: of_find: %s", strerror(errno) );
+ err = AFPERR_PARAM;
+ goto afp_write_err;
+ }
+
+ if ((ofork->of_flags & AFPFORK_ACCWR) == 0) {
+ err = AFPERR_ACCESS;
+ goto afp_write_err;
+ }
#ifdef AFS
- writtenfork = ofork;
+ writtenfork = ofork;
#endif /* AFS */
- if ( ofork->of_flags & AFPFORK_DATA) {
- eid = ADEID_DFORK;
- xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0;
- } else if (ofork->of_flags & AFPFORK_RSRC) {
- eid = ADEID_RFORK;
- } else {
- err = AFPERR_ACCESS; /* should never happen */
- goto afp_write_err;
- }
-
- if (endflag)
- offset += ad_size(ofork->of_ad, eid);
-
- /* handle bogus parameters */
- if (reqcount < 0 || offset < 0) {
- err = AFPERR_PARAM;
- goto afp_write_err;
- }
-
- /* offset can overflow on 64-bit capable filesystems.
- * report disk full if that's going to happen. */
- if (offset + reqcount < 0) {
- err = AFPERR_DFULL;
- goto afp_write_err;
- }
+ if ( ofork->of_flags & AFPFORK_DATA) {
+ eid = ADEID_DFORK;
+ xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0;
+ } else if (ofork->of_flags & AFPFORK_RSRC) {
+ eid = ADEID_RFORK;
+ } else {
+ err = AFPERR_ACCESS; /* should never happen */
+ goto afp_write_err;
+ }
- if (!reqcount) { /* handle request counts of 0 */
- err = AFP_OK;
- offset = htonl(offset);
- memcpy(rbuf, &offset, sizeof(offset));
- goto afp_write_err;
- }
+ if (endflag)
+ offset += ad_size(ofork->of_ad, eid);
- saveoff = offset;
- if (ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, saveoff,
- reqcount) < 0) {
- err = AFPERR_LOCK;
- goto afp_write_err;
- }
+ /* handle bogus parameters */
+ if (reqcount < 0 || offset < 0) {
+ err = AFPERR_PARAM;
+ goto afp_write_err;
+ }
- /* this is yucky, but dsi can stream i/o and asp can't */
- switch (obj->proto) {
-#ifndef NO_DDP
- case AFPPROTO_ASP:
- if (asp_wrtcont(obj->handle, rbuf, rbuflen) < 0) {
- *rbuflen = 0;
- LOG(log_error, logtype_default, "afp_write: asp_wrtcont: %s", strerror(errno) );
- return( AFPERR_PARAM );
+ /* offset can overflow on 64-bit capable filesystems.
+ * report disk full if that's going to happen. */
+ if (offset + reqcount < 0) {
+ err = AFPERR_DFULL;
+ goto afp_write_err;
}
- if (obj->options.flags & OPTION_DEBUG) {
- printf("(write) len: %d\n", *rbuflen);
- bprint(rbuf, *rbuflen);
+ if (!reqcount) { /* handle request counts of 0 */
+ err = AFP_OK;
+ offset = htonl(offset);
+ memcpy(rbuf, &offset, sizeof(offset));
+ goto afp_write_err;
}
- if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen,
- xlate)) < 0) {
- *rbuflen = 0;
- ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
- return cc;
+ saveoff = offset;
+ if (ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, saveoff,
+ reqcount) < 0) {
+ err = AFPERR_LOCK;
+ goto afp_write_err;
}
- offset += cc;
- break;
-#endif /* no afp/asp */
- case AFPPROTO_DSI:
- {
- DSI *dsi = obj->handle;
+ /* this is yucky, but dsi can stream i/o and asp can't */
+ switch (obj->proto) {
+#ifndef NO_DDP
+ case AFPPROTO_ASP:
+ if (asp_wrtcont(obj->handle, rbuf, rbuflen) < 0) {
+ *rbuflen = 0;
+ LOG(log_error, logtype_default, "afp_write: asp_wrtcont: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
+
+ if (obj->options.flags & OPTION_DEBUG) {
+ printf("(write) len: %d\n", *rbuflen);
+ bprint(rbuf, *rbuflen);
+ }
- /* find out what we have already and write it out. */
- cc = dsi_writeinit(dsi, rbuf, *rbuflen);
- if (!cc ||
- (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
- dsi_writeflush(dsi);
+ if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen,
+ xlate)) < 0) {
*rbuflen = 0;
ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
return cc;
}
offset += cc;
+ break;
+#endif /* no afp/asp */
-#if 0 /*def HAVE_SENDFILE_WRITE*/
- if (!(xlate || obj->options.flags & OPTION_DEBUG)) {
- if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket,
- offset, dsi->datasize)) < 0) {
- switch (errno) {
- case EDQUOT :
- case EFBIG :
- case ENOSPC :
- cc = AFPERR_DFULL;
- break;
- default :
- LOG(log_error, logtype_default, "afp_write: ad_writefile: %s", strerror(errno) );
- goto afp_write_loop;
- }
+ case AFPPROTO_DSI:
+ {
+ DSI *dsi = obj->handle;
+
+ /* find out what we have already and write it out. */
+ cc = dsi_writeinit(dsi, rbuf, *rbuflen);
+ if (!cc ||
+ (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
dsi_writeflush(dsi);
*rbuflen = 0;
- ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
- reqcount);
+ ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
return cc;
}
-
offset += cc;
- goto afp_write_done;
- }
+
+#if 0 /*def HAVE_SENDFILE_WRITE*/
+ if (!(xlate || obj->options.flags & OPTION_DEBUG)) {
+ if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket,
+ offset, dsi->datasize)) < 0) {
+ switch (errno) {
+ case EDQUOT :
+ case EFBIG :
+ case ENOSPC :
+ cc = AFPERR_DFULL;
+ break;
+ default :
+ LOG(log_error, logtype_default, "afp_write: ad_writefile: %s", strerror(errno) );
+ goto afp_write_loop;
+ }
+ dsi_writeflush(dsi);
+ *rbuflen = 0;
+ ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
+ reqcount);
+ return cc;
+ }
+
+ offset += cc;
+ goto afp_write_done;
+ }
#endif /* 0, was HAVE_SENDFILE_WRITE */
- /* loop until everything gets written. currently
- * dsi_write handles the end case by itself. */
+ /* loop until everything gets written. currently
+ * dsi_write handles the end case by itself. */
afp_write_loop:
- while ((cc = dsi_write(dsi, rbuf, *rbuflen))) {
- if ( obj->options.flags & OPTION_DEBUG ) {
- printf("(write) command cont'd: %d\n", cc);
- bprint(rbuf, cc);
- }
+ while ((cc = dsi_write(dsi, rbuf, *rbuflen))) {
+ if ( obj->options.flags & OPTION_DEBUG ) {
+ printf("(write) command cont'd: %d\n", cc);
+ bprint(rbuf, cc);
+ }
- if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
- dsi_writeflush(dsi);
- *rbuflen = 0;
- ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
- reqcount);
- return cc;
+ if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
+ dsi_writeflush(dsi);
+ *rbuflen = 0;
+ ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
+ reqcount);
+ return cc;
+ }
+ offset += cc;
}
- offset += cc;
}
+ break;
}
- break;
- }
afp_write_done:
- ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
- if ( ad_hfileno( ofork->of_ad ) != -1 )
- ofork->of_flags |= AFPFORK_DIRTY;
+ ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
+ if ( ad_hfileno( ofork->of_ad ) != -1 )
+ ofork->of_flags |= AFPFORK_DIRTY;
- offset = htonl( offset );
+ offset = htonl( offset );
#if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
- bcopy(&offset, rbuf, sizeof(offset));
+ bcopy(&offset, rbuf, sizeof(offset));
#else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
- memcpy(rbuf, &offset, sizeof(offset));
+ memcpy(rbuf, &offset, sizeof(offset));
#endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
- *rbuflen = sizeof(offset);
- return( AFP_OK );
+ *rbuflen = sizeof(offset);
+ return( AFP_OK );
afp_write_err:
- if (obj->proto == AFPPROTO_DSI) {
- dsi_writeinit(obj->handle, rbuf, *rbuflen);
- dsi_writeflush(obj->handle);
+ if (obj->proto == AFPPROTO_DSI) {
+ dsi_writeinit(obj->handle, rbuf, *rbuflen);
+ dsi_writeflush(obj->handle);
+ }
+
+ *rbuflen = (err == AFP_OK) ? sizeof(offset) : 0;
+ return err;
}
- *rbuflen = (err == AFP_OK) ? sizeof(offset) : 0;
- return err;
-}
+ int afp_getforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
+ AFPObj *obj;
+ char *ibuf, *rbuf;
+ int ibuflen, *rbuflen;
+ {
+ struct ofork *ofork;
+ int buflen, ret;
+ u_int16_t ofrefnum, bitmap;
-int afp_getforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
-{
- struct ofork *ofork;
- int buflen, ret;
- u_int16_t ofrefnum, bitmap;
-
- ibuf += 2;
- memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
- ibuf += sizeof( ofrefnum );
- memcpy(&bitmap, ibuf, sizeof( bitmap ));
- bitmap = ntohs( bitmap );
- ibuf += sizeof( bitmap );
-
- *rbuflen = 0;
- if (( ofork = of_find( ofrefnum )) == NULL ) {
- LOG(log_error, logtype_default, "afp_getforkparams: of_find: %s", strerror(errno) );
- return( AFPERR_PARAM );
- }
+ ibuf += 2;
+ memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
+ ibuf += sizeof( ofrefnum );
+ memcpy(&bitmap, ibuf, sizeof( bitmap ));
+ bitmap = ntohs( bitmap );
+ ibuf += sizeof( bitmap );
- if (( ret = getforkparams( ofork, bitmap,
- rbuf + sizeof( u_short ), &buflen, 0 )) != AFP_OK ) {
- return( ret );
- }
+ *rbuflen = 0;
+ if (( ofork = of_find( ofrefnum )) == NULL ) {
+ LOG(log_error, logtype_default, "afp_getforkparams: of_find: %s", strerror(errno) );
+ return( AFPERR_PARAM );
+ }
- *rbuflen = buflen + sizeof( u_short );
- bitmap = htons( bitmap );
- memcpy(rbuf, &bitmap, sizeof( bitmap ));
- return( AFP_OK );
-}
+ if (( ret = getforkparams( ofork, bitmap,
+ rbuf + sizeof( u_short ), &buflen, 0 )) != AFP_OK ) {
+ return( ret );
+ }
+
+ *rbuflen = buflen + sizeof( u_short );
+ bitmap = htons( bitmap );
+ memcpy(rbuf, &bitmap, sizeof( bitmap ));
+ return( AFP_OK );
+ }
#include <netatalk/endian.h>
+#define CNID_ERR_PARAM 0x80000001
+#define CNID_ERR_PATH 0x80000002
+#define CNID_ERR_DB 0x80000003
+#define CNID_ERR_MAX 0x80000004
+
+#define CNID_MAX 0x80000000
+
typedef u_int32_t cnid_t;
/* cnid_open.c */
/*
- * $Id: cnid_add.c,v 1.20 2002-01-04 04:45:48 sibaz Exp $
+ * $Id: cnid_add.c,v 1.21 2002-01-17 16:19:07 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#include "cnid_private.h"
-#define MAX_ABORTS 255
-
/* add an entry to the CNID databases. we do this as a transaction
* to prevent messiness. */
-static int add_cnid(CNID_private *db, DB_TXN *ptid, DBT *key, DBT *data) {
+static int add_cnid(CNID_private *db, DBT *key, DBT *data) {
DBT altkey, altdata;
DB_TXN *tid;
/* We create rc here because using errno is bad. Why? Well, if you
* use errno once, then call another function which resets it, you're
* screwed. */
- int rc, ret, aborts = 0;
+ int rc, ret;
memset(&altkey, 0, sizeof(altkey));
memset(&altdata, 0, sizeof(altdata));
- if (0) {
retry:
- if ((rc = txn_abort(tid)) != 0) {
- return rc;
- }
- if (++aborts > MAX_ABORTS) {
- return DB_LOCK_DEADLOCK;
- }
- }
-
- if ((rc = txn_begin(db->dbenv, ptid, &tid, 0)) != 0) {
+ if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
return rc;
}
if (rc == DB_LOCK_DEADLOCK) {
goto retry;
}
-
goto abort;
}
-
/* dev/ino database */
altkey.data = data->data;
altkey.size = CNID_DEVINO_LEN;
if (rc == DB_LOCK_DEADLOCK) {
goto retry;
}
-
goto abort;
}
-
/* did/name database */
altkey.data = (char *) data->data + CNID_DEVINO_LEN;
altkey.size = data->size - CNID_DEVINO_LEN;
if (rc == DB_LOCK_DEADLOCK) {
goto retry;
}
-
goto abort;
}
if ((rc = txn_commit(tid, 0)) != 0) {
- LOG(log_error, logtype_default, "add_cnid: Failed to commit transaction: %s",
- db_strerror(rc));
+ LOG(log_error, logtype_default, "add_cnid: Failed to commit transaction: %s", db_strerror(rc));
return rc;
}
+
return 0;
abort:
return ret;
}
return rc;
-
}
cnid_t cnid_add(void *CNID, const struct stat *st,
int rc;
if (!(db = CNID) || !st || !name) {
- return 0;
+ return CNID_ERR_PARAM;
}
/* Do a lookup. */
if (id || (db->flags & CNIDFLAG_DB_RO)) {
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_add: Looked up did %u, name %s as %u",
- ntohl(did), name, ntohl(id));
+ ntohl(did), name, ntohl(id));
#endif
return id;
}
if ((data.data = make_cnid_data(st, did, name, len)) == NULL) {
LOG(log_error, logtype_default, "cnid_add: Path name is too long");
- goto cleanup_err;
+ return CNID_ERR_PATH;
}
data.size = CNID_HEADER_LEN + len + 1;
* cnid's to the database. */
if (ntohl(hint) >= CNID_START) {
/* If the key doesn't exist, add it in. Don't fiddle with nextID. */
- rc = add_cnid(db, NULL, &key, &data);
+ rc = add_cnid(db, &key, &data);
switch (rc) {
case DB_KEYEXIST: /* Need to use RootInfo after all. */
break;
default:
LOG(log_error, logtype_default, "cnid_add: Unable to add CNID %u: %s",
- ntohl(hint), db_strerror(rc));
- goto cleanup_err;
+ ntohl(hint), db_strerror(rc));
+ return CNID_ERR_DB;
case 0:
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_add: Used hint for did %u, name %s as %u",
- ntohl(did), name, ntohl(hint));
+ ntohl(did), name, ntohl(hint));
#endif
return hint;
}
}
/* We need to create a random sleep interval to prevent deadlocks. */
- (void)srand(getpid() ^ time(NULL));
- t.tv_sec = 0;
+ /*(void)srand(getpid() ^ time(NULL));
+ t.tv_sec = 0;*/
memset(&rootinfo_key, 0, sizeof(rootinfo_key));
memset(&rootinfo_data, 0, sizeof(rootinfo_data));
rootinfo_key.data = ROOTINFO_KEY;
rootinfo_key.size = ROOTINFO_KEYLEN;
+retry:
+ if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
+ LOG(log_error, logtype_default, "cnid_add: Failed to begin transaction: %s", db_strerror(rc));
+ return CNID_ERR_DB;
+ }
+
/* Get the key. */
-retry_get:
- switch (rc = db->db_didname->get(db->db_didname, NULL, &rootinfo_key,
- &rootinfo_data, 0)) {
+ switch (rc = db->db_didname->get(db->db_didname, tid, &rootinfo_key,
+ &rootinfo_data, DB_RMW)) {
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc));
- goto cleanup_err;
+ return CNID_ERR_DB;
}
- goto retry_get;
+ goto retry;
case 0:
memcpy(&hint, rootinfo_data.data, sizeof(hint));
#ifdef DEBUG
hint = htonl(CNID_START);
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_add: Using CNID_START for did %u, name %s",
- ntohl(did), name);
+ ntohl(did), name);
#endif
break;
default:
- LOG(log_error, logtype_default, "cnid_add: Unable to lookup rootinfo: %s",
- db_strerror(rc));
- goto cleanup_err;
+ LOG(log_error, logtype_default, "cnid_add: Unable to lookup rootinfo: %s", db_strerror(rc));
+ goto cleanup_abort;
}
-
- if (0) {
-retry:
- t.tv_usec = rand() % 1000000;
-#ifdef DEBUG
- LOG(log_info, logtype_default, "cnid_add: Hitting MAX_ABORTS, sleeping");
-#endif
- (void)select(0, NULL, NULL, NULL, &t);
+ id = ntohl(hint);
+ if (id <= CNID_START) {
+ id = CNID_START;
}
- if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
- LOG(log_error, logtype_default, "cnid_add: Failed to begin transaction: %s",
- db_strerror(rc));
- goto cleanup_err;
+ else {
+ id++;
}
- /* Search for a new id. We keep the first id around to check for
- * wrap-around. NOTE: I do it this way so that we can go back and
- * fill in holes. */
- save = id = ntohl(hint);
- while ((rc = add_cnid(db, tid, &key, &data)) != 0) {
- /* Don't use any special CNIDs. */
- if (++id < CNID_START) {
- id = CNID_START;
- }
- if (rc == DB_LOCK_DEADLOCK) {
- if ((rc = txn_abort(tid)) != 0) {
- LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc));
- goto cleanup_err;
- }
- goto retry;
- }
-
- if ((rc != DB_KEYEXIST) || (save == id)) {
- LOG(log_error, logtype_default, "cnid_add: Unable to add CNID %u: %s",
- ntohl(hint), db_strerror(rc));
- goto cleanup_abort;
- }
- hint = htonl(id);
+ /* If we've hit the MAX CNID allowed, we return a fatal error. CNID needs
+ * to be recycled before proceding. */
+ if (id == CNID_MAX) {
+ txn_abort(tid);
+ LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s. CNID database has reached its limit.", name);
+ return CNID_ERR_MAX;
}
+ hint = htonl(id);
+
rootinfo_data.data = &hint;
rootinfo_data.size = sizeof(hint);
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc));
- goto cleanup_err;
+ return CNID_ERR_DB;
}
goto retry;
case 0:
break;
default:
- LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s",
- db_strerror(rc));
+ LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc));
goto cleanup_abort;
}
-cleanup_commit:
/* The transaction finished, commit it. */
if ((rc = txn_commit(tid, 0)) != 0) {
- LOG(log_error, logtype_default, "cnid_add: Unable to commit transaction: %s",
- db_strerror(rc));
- goto cleanup_err;
+ LOG(log_error, logtype_default, "cnid_add: Unable to commit transaction: %s", db_strerror(rc));
+ return CNID_ERR_DB;
+ }
+
+ /* Now we need to add the CNID data to the databases. */
+ rc = add_cnid(db, &key, &data);
+ if (rc) {
+ LOG(log_error, logtype_default, "cnid_add: Failed to add CNID for %s to database using hint %u", name, ntohl(hint));
+ return CNID_ERR_DB;
}
#ifdef DEBUG
- LOG(log_info, logtype_default, "cnid_add: Returned CNID for did %u, name %s as %u",
- ntohl(did), name, ntohl(hint));
+ LOG(log_info, logtype_default, "cnid_add: Returned CNID for did %u, name %s as %u", ntohl(did), name, ntohl(hint));
#endif
+
return hint;
cleanup_abort:
txn_abort(tid);
-cleanup_err:
- return 0;
+ return CNID_ERR_DB;
}
#endif /* CNID_DB */
/*
- * $Id: cnid_open.c,v 1.30 2002-01-04 04:45:48 sibaz Exp $
+ * $Id: cnid_open.c,v 1.31 2002-01-17 16:19:07 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
DB_INIT_LOG | DB_INIT_TXN)*/
#endif /* DB_VERSION_MINOR */
-/* Let's try and use the random deadlock decider if available. This adds
- * a bit of entropy to the mix that might be beneficial. If random isn't
- * available, we'll decide deadlocks by kicking off the youngest process.
+/* Let's try and use the youngest lock detector if present.
* If we can't do that, then let DB3 use its default deadlock detector. */
-#ifdef DB_LOCK_RANDOM
-#define DEAD_LOCK_DETECT DB_LOCK_RANDOM
-#elif defined DB_LOCK_YOUNGEST
+#if defined DB_LOCK_YOUNGEST
#define DEAD_LOCK_DETECT DB_LOCK_YOUNGEST
-#else /* DB_LOCK_RANDOM */
+#else /* DB_LOCK_YOUNGEST */
#define DEAD_LOCK_DETECT DB_LOCK_DEFAULT
-#endif /* DB_LOCK_RANDOM */
+#endif /* DB_LOCK_YOUNGEST */
#define MAXITER 0xFFFF /* maximum number of simultaneously open CNID
* databases. */
* open the environment with no flags. */
if ((rc = db->dbenv->open(db->dbenv, path, 0, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: dbenv->open of %s failed: %s",
- path, db_strerror(rc));
+ path, db_strerror(rc));
goto fail_lock;
}
}
break;
default:
LOG(log_error, logtype_default, "cnid_open: Unable to remove %s: %s",
- recover_file, strerror(errno));
+ recover_file, strerror(errno));
}
close(rfd);
rfd = -1;
/* did/name reverse mapping. We use a BTree for this one. */
if ((rc = db_create(&db->db_didname, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create did/name database: %s",
- db_strerror(rc));
+ db_strerror(rc));
goto fail_appinit;
}
if ((rc = db->db_didname->open(db->db_didname, DBDIDNAME, NULL,
DB_BTREE, open_flag, 0666))) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/name database: %s",
- db_strerror(rc));
+ db_strerror(rc));
goto fail_appinit;
}
dbversion_retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: txn_begin: failed to check db version: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
if (ret == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_open: txn_abort: %s",
- db_strerror(ret));
+ db_strerror(ret));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
* successfully or not. */
txn_abort(tid);
LOG(log_error, logtype_default, "cnid_open: Error putting new version: %s",
- db_strerror(ret));
+ db_strerror(ret));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
default:
txn_abort(tid);
LOG(log_error, logtype_default, "cnid_open: Failed to check db version: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to commit db version: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
/* did/macname (31 character) mapping. Use a BTree for this one. */
if ((rc = db_create(&db->db_macname, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create did/macname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
db->db_macname->set_bt_compare(db->db_macname, &compare_mac);
if ((rc = db->db_macname->open(db->db_macname, DBMACNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/macname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
/* did/shortname (DOS 8.3) mapping. Use a BTree for this one. */
if ((rc = db_create(&db->db_shortname, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create did/shortname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
db->db_macname->close(db->db_macname, 0);
goto fail_appinit;
db->db_shortname->set_bt_compare(db->db_shortname, &compare_mac);
if ((rc = db->db_shortname->open(db->db_shortname, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/shortname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
db->db_macname->close(db->db_macname, 0);
goto fail_appinit;
/* did/longname (Unicode) mapping. Use a BTree for this one. */
if ((rc = db_create(&db->db_longname, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create did/longname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
db->db_macname->close(db->db_macname, 0);
db->db_shortname->close(db->db_shortname, 0);
db->db_longname->set_bt_compare(db->db_longname, &compare_unicode);
if ((rc = db->db_longname->open(db->db_longname, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/longname database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
db->db_macname->close(db->db_macname, 0);
db->db_shortname->close(db->db_shortname, 0);
/* dev/ino reverse mapping. Use a hash for this one. */
if ((rc = db_create(&db->db_devino, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create dev/ino database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
#ifdef EXTENDED_DB
db->db_macname->close(db->db_macname, 0);
if ((rc = db->db_devino->open(db->db_devino, DBDEVINO, NULL, DB_HASH, open_flag, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open devino database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
#ifdef EXTENDED_DB
db->db_macname->close(db->db_macname, 0);
/* Main CNID database. Use a hash for this one. */
if ((rc = db_create(&db->db_cnid, db->dbenv, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to create cnid database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
#ifdef EXTENDED_DB
db->db_macname->close(db->db_macname, 0);
if ((rc = db->db_cnid->open(db->db_cnid, DBCNID, NULL, DB_HASH, open_flag, 0666)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open dev/ino database: %s",
- db_strerror(rc));
+ db_strerror(rc));
db->db_didname->close(db->db_didname, 0);
#ifdef EXTENDED_DB
db->db_macname->close(db->db_macname, 0);