- /* use the CNID database if we're using AD v2 */
- if (isad)
- memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint));
- else
- aint = 0;
-
- if (!(aint = cnid_add(vol->v_db, st, dir->d_did, upath,
- strlen(upath), aint))) {
-#endif
- /*
- * 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.
- */
- lstp = (lstat(upath, &lst) < 0) ? st : &lst;
- aint = htonl(CNID(lstp, 1));
-#if AD_VERSION > AD_VERSION1
- }
-#endif
- 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;
-
- /* 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;
- }
-
- *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 );
- }
- return( AFPERR_BITMAP );
- }
- bitmap = bitmap>>1;
- bit++;
+ /* look in AD v2 header */
+ if (isad)
+ memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint));
+#endif /* AD_VERSION > AD_VERSION1 */
+
+#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_INVALID) {
+ switch (errno) {
+ 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.
+ */
+#ifdef USE_LASTDID
+ aint = htonl(( st->st_dev << 16 ) | (st->st_ino & 0x0000ffff));
+#else /* USE_LASTDID */
+ lstp = lstat(upath, &lst) < 0 ? st : &lst;
+#ifdef DID_MTAB
+ aint = htonl( afpd_st_cnid ( lstp ) );
+#else /* DID_MTAB */
+ 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;
+
+ /* 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;
+ }
+
+ *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 );
+ }
+ return( AFPERR_BITMAP );
+ }
+ bitmap = bitmap>>1;
+ bit++;