- switch ( bit ) {
- case FILPBIT_ATTR :
- if ( isad ) {
- ad_getattr(adp, &ashort);
- } else if (*upath == '.') {
- ashort = htons(ATTRBIT_INVISIBLE);
- } else
- ashort = 0;
- memcpy(data, &ashort, sizeof( ashort ));
- data += sizeof( u_short );
- break;
-
- case FILPBIT_PDID :
- memcpy(data, &dir->d_did, sizeof( u_int32_t ));
- data += sizeof( u_int32_t );
- break;
-
- case FILPBIT_CDATE :
- if (!isad || (ad_getdate(adp, AD_DATE_CREATE, &aint) < 0))
- aint = AD_DATE_FROM_UNIX(st->st_mtime);
- memcpy(data, &aint, sizeof( aint ));
- data += sizeof( aint );
- break;
-
- case FILPBIT_MDATE :
- if ( isad && (ad_getdate(adp, AD_DATE_MODIFY, &aint) == 0)) {
- if ((st->st_mtime > AD_DATE_TO_UNIX(aint)) &&
- (hst.st_mtime < st->st_mtime)) {
- aint = AD_DATE_FROM_UNIX(st->st_mtime);
- }
- } else {
- aint = AD_DATE_FROM_UNIX(st->st_mtime);
- }
- memcpy(data, &aint, sizeof( int ));
- data += sizeof( int );
- break;
-
- case FILPBIT_BDATE :
- if (!isad || (ad_getdate(adp, AD_DATE_BACKUP, &aint) < 0))
- aint = AD_DATE_START;
- memcpy(data, &aint, sizeof( int ));
- data += sizeof( int );
- break;
-
- case FILPBIT_FINFO :
- if (isad)
- memcpy(data, ad_entry(adp, ADEID_FINDERI), 32);
- else {
- memcpy(data, ufinderi, 32);
- if (*upath == '.') { /* make it invisible */
- ashort = htons(FINDERINFO_INVISIBLE);
- memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
- }
- }
-
- if ((!isad || (memcmp(ad_entry(adp, ADEID_FINDERI),
- ufinderi, 8 ) == 0)) &&
- (em = getextmap( path ))) {
- memcpy(data, em->em_type, sizeof( em->em_type ));
- memcpy(data + 4, em->em_creator, sizeof(em->em_creator));
- }
- data += 32;
- break;
-
- case FILPBIT_LNAME :
- nameoff = data;
- data += sizeof( u_int16_t );
- break;
-
- case FILPBIT_SNAME :
- memset(data, 0, sizeof(u_int16_t));
- data += sizeof( u_int16_t );
- break;
-
- case FILPBIT_FNUM :
- aint = 0;
-#if AD_VERSION > AD_VERSION1
- /* 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);
-#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 );
+ if ( ((bitmap & ( (1 << FILPBIT_FINFO)|(1 << FILPBIT_LNAME)|(1 <<FILPBIT_PDINFO) ) ) && !path->m_name)
+ || (bitmap & ( (1 << FILPBIT_LNAME) ) && utf8_encoding()) /* FIXME should be m_name utf8 filename */
+ || (bitmap & (1 << FILPBIT_FNUM))) {
+ if (!path->id)
+ id = get_id(vol, adp, st, dir->d_did, upath, strlen(upath));
+ else
+ id = path->id;
+ if (id == 0)
+ return afp_errno;
+ if (!path->m_name) {
+ path->m_name = utompath(vol, upath, id, utf8_encoding());
+ }
+ }
+ while ( bitmap != 0 ) {
+ while (( bitmap & 1 ) == 0 ) {
+ bitmap = bitmap>>1;
+ bit++;
+ }
+
+ switch ( bit ) {
+ case FILPBIT_ATTR :
+ if ( adp ) {
+ ad_getattr(adp, &ashort);
+ } else if (vol_inv_dots(vol) && *upath == '.') {
+ ashort = htons(ATTRBIT_INVISIBLE);
+ } else
+ ashort = 0;
+#if 0
+ /* FIXME do we want a visual clue if the file is read only
+ */
+ struct maccess ma;
+ accessmode( ".", &ma, dir , NULL);
+ if ((ma.ma_user & AR_UWRITE)) {
+ accessmode( upath, &ma, dir , st);
+ if (!(ma.ma_user & AR_UWRITE)) {
+ ashort |= htons(ATTRBIT_NOWRITE);
+ }
+ }
+#endif
+ memcpy(data, &ashort, sizeof( ashort ));
+ data += sizeof( ashort );
+ break;
+
+ case FILPBIT_PDID :
+ memcpy(data, &dir->d_did, sizeof( u_int32_t ));
+ data += sizeof( u_int32_t );
+ break;
+
+ case FILPBIT_CDATE :
+ if (!adp || (ad_getdate(adp, AD_DATE_CREATE, &aint) < 0))
+ aint = AD_DATE_FROM_UNIX(st->st_mtime);
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
+
+ case FILPBIT_MDATE :
+ if ( adp && (ad_getdate(adp, AD_DATE_MODIFY, &aint) == 0)) {
+ if ((st->st_mtime > AD_DATE_TO_UNIX(aint))) {
+ aint = AD_DATE_FROM_UNIX(st->st_mtime);
+ }
+ } else {
+ aint = AD_DATE_FROM_UNIX(st->st_mtime);
+ }
+ memcpy(data, &aint, sizeof( int ));
+ data += sizeof( int );
+ break;
+
+ case FILPBIT_BDATE :
+ if (!adp || (ad_getdate(adp, AD_DATE_BACKUP, &aint) < 0))
+ aint = AD_DATE_START;
+ memcpy(data, &aint, sizeof( int ));
+ data += sizeof( int );
+ break;
+
+ case FILPBIT_FINFO :
+ get_finderinfo(vol, upath, adp, (char *)data);
+ data += ADEDLEN_FINDERI;
+ break;
+
+ case FILPBIT_LNAME :
+ l_nameoff = data;
+ data += sizeof( u_int16_t );
+ break;
+
+ case FILPBIT_SNAME :
+ memset(data, 0, sizeof(u_int16_t));
+ data += sizeof( u_int16_t );
+ break;
+
+ case FILPBIT_FNUM :
+ memcpy(data, &id, sizeof( id ));
+ data += sizeof( id );
+ break;
+
+ case FILPBIT_DFLEN :
+ if (st->st_size > 0xffffffff)
+ aint = 0xffffffff;
+ else
+ aint = htonl( st->st_size );
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
+
+ case FILPBIT_RFLEN :
+ if ( adp ) {
+ if (adp->ad_rlen > 0xffffffff)
+ aint = 0xffffffff;
+ else
+ aint = htonl( adp->ad_rlen);
+ } 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@adelphia.net> */
+ case FILPBIT_PDINFO :
+ if (afp_version >= 30) { /* UTF8 name */
+ utf8 = kTextEncodingUTF8;
+ utf_nameoff = data;
+ data += sizeof( u_int16_t );
+ aint = 0;
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ }
+ else {
+ if ( adp ) {
+ 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;
+ case FILPBIT_EXTDFLEN:
+ aint = htonl(st->st_size >> 32);
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ aint = htonl(st->st_size);
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
+ case FILPBIT_EXTRFLEN:
+ aint = 0;
+ if (adp)
+ aint = htonl(adp->ad_rlen >> 32);
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ if (adp)
+ aint = htonl(adp->ad_rlen);
+ memcpy(data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ break;
+ case FILPBIT_UNIXPR :
+ /* accessmode may change st_mode with ACLs */
+ accessmode( upath, &ma, dir , st);
+
+ aint = htonl(st->st_uid);
+ memcpy( data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+ aint = htonl(st->st_gid);
+ memcpy( data, &aint, sizeof( aint ));
+ data += sizeof( aint );
+
+ /* FIXME: ugly hack
+ type == slnk indicates an OSX style symlink,
+ we have to add S_IFLNK to the mode, otherwise
+ 10.3 clients freak out. */
+
+ aint = st->st_mode;
+ if (adp) {
+ memcpy(fdType, ad_entry( adp, ADEID_FINDERI ), 4 );
+ if ( memcmp( fdType, "slnk", 4 ) == 0 ) {
+ aint |= S_IFLNK;
+ }