+static const u_char old_ufinderi[] = {
+ 'T', 'E', 'X', 'T', 'U', 'N', 'I', 'X'
+ };
+
+/* ----------------------
+*/
+static int default_type(void *finder)
+{
+ if (!memcmp(finder, ufinderi, 8) || !memcmp(finder, old_ufinderi, 8))
+ return 1;
+ return 0;
+}
+
+/* FIXME path : unix or mac name ? (for now it's unix name ) */
+void *get_finderinfo(const char *upath, struct adouble *adp, void *data)
+{
+ struct extmap *em;
+ void *ad_finder = NULL;
+ int chk_ext = 0;
+
+ if (adp)
+ ad_finder = ad_entry(adp, ADEID_FINDERI);
+
+ if (ad_finder) {
+ memcpy(data, ad_finder, ADEDLEN_FINDERI);
+ /* default type ? */
+ if (default_type(ad_finder))
+ chk_ext = 1;
+ }
+ else {
+ memcpy(data, ufinderi, ADEDLEN_FINDERI);
+ chk_ext = 1;
+ if (*upath == '.') { /* make it invisible */
+ u_int16_t ashort;
+
+ ashort = htons(FINDERINFO_INVISIBLE);
+ memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
+ }
+ }
+ /** Only enter if no appledouble information and no finder information found. */
+ if (chk_ext && (em = getextmap( upath ))) {
+ memcpy(data, em->em_type, sizeof( em->em_type ));
+ memcpy((char *)data + 4, em->em_creator, sizeof(em->em_creator));
+ }
+ return data;
+}
+
+/* ---------------------
+*/
+char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t id, u_int32_t utf8)
+{
+ u_int32_t aint;
+ char *tp = NULL;
+ char *src = name;
+ aint = strlen( name );
+
+ if (!utf8) {
+ /* want mac name */
+ if (utf8_encoding()) {
+ /* but name is an utf8 mac name */
+ char *u, *m;
+
+ /* global static variable... */
+ tp = strdup(name);
+ if (!(u = mtoupath(vol, name, pid, 1)) || !(m = utompath(vol, u, id, 0))) {
+ aint = 0;
+ }
+ else {
+ aint = strlen(m);
+ src = m;
+ }
+
+ }
+ if (aint > MACFILELEN)
+ aint = MACFILELEN;
+ *data++ = aint;
+ }
+ else {
+ u_int16_t temp;
+
+ if (aint > 255) /* FIXME safeguard, anyway if no ascii char it's game over*/
+ aint = 255;
+
+ utf8 = vol->v_mac?htonl(vol->v_mac->kTextEncoding):0; /* htonl(utf8) */
+ memcpy(data, &utf8, sizeof(utf8));
+ data += sizeof(utf8);
+
+ temp = htons(aint);
+ memcpy(data, &temp, sizeof(temp));
+ data += sizeof(temp);
+ }
+
+ memcpy( data, src, aint );
+ data += aint;
+ if (tp) {
+ strcpy(name, tp);
+ free(tp);
+ }
+ return data;
+}
+
+/*
+ * FIXME: PDINFO is UTF8 and doesn't need adp
+*/
+#define PARAM_NEED_ADP(b) ((b) & ((1 << FILPBIT_ATTR) |\
+ (1 << FILPBIT_CDATE) |\
+ (1 << FILPBIT_MDATE) |\
+ (1 << FILPBIT_BDATE) |\
+ (1 << FILPBIT_FINFO) |\
+ (1 << FILPBIT_RFLEN) |\
+ (1 << FILPBIT_EXTRFLEN) |\
+ (1 << FILPBIT_PDINFO) |\
+ (1 << FILPBIT_UNIXPR)))
+
+/* -------------------------- */
+u_int32_t get_id(struct vol *vol, struct adouble *adp, const struct stat *st,
+ const cnid_t did, char *upath, const int len)
+{
+u_int32_t aint = 0;
+
+#if AD_VERSION > AD_VERSION1
+
+ if ((aint = ad_getid(adp, st->st_dev, st->st_ino, did, vol->v_stamp))) {
+ return aint;
+ }
+#endif
+
+ if (vol->v_cdb != NULL) {
+ aint = cnid_add(vol->v_cdb, st, did, upath, len, aint);
+ /* Throw errors if cnid_add fails. */
+ if (aint == CNID_INVALID) {
+ switch (errno) {
+ case CNID_ERR_CLOSE: /* the db is closed */
+ break;
+ case CNID_ERR_PARAM:
+ LOG(log_error, logtype_afpd, "get_id: Incorrect parameters passed to cnid_add");
+ afp_errno = AFPERR_PARAM;
+ return CNID_INVALID;
+ case CNID_ERR_PATH:
+ afp_errno = AFPERR_PARAM;
+ return CNID_INVALID;
+ default:
+ afp_errno = AFPERR_MISC;
+ return CNID_INVALID;
+ }
+ }
+#if AD_VERSION > AD_VERSION1
+ else if (adp ) {
+ /* update the ressource fork
+ * for a folder adp is always null
+ */
+ if (ad_setid(adp, st->st_dev, st->st_ino, aint, did, vol->v_stamp)) {
+ ad_flush(adp, ADFLAGS_HF);
+ }
+ }
+#endif
+ }
+ return aint;
+}
+
+/* -------------------------- */