- const unsigned char *old_name, *new_name;
- struct qstr *old_qstr, *new_qstr;
-
- memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
- old_qstr = target->d_qstr;
- old_name = target->d_name.name;
- new_qstr = dentry->d_qstr;
- new_name = dentry->d_name.name;
- if (old_name == target->d_iname) {
- old_name = dentry->d_iname;
- old_qstr = &dentry->d_name;
- }
- if (new_name == dentry->d_iname) {
- new_name = target->d_iname;
- new_qstr = &target->d_name;
+ if (dname_external(target)) {
+ if (dname_external(dentry)) {
+ /*
+ * Both external: swap the pointers
+ */
+ do_switch(target->d_name.name, dentry->d_name.name);
+ } else {
+ /*
+ * dentry:internal, target:external. Steal target's
+ * storage and make target internal.
+ */
+ dentry->d_name.name = target->d_name.name;
+ target->d_name.name = target->d_iname;
+ }
+ } else {
+ if (dname_external(dentry)) {
+ /*
+ * dentry:external, target:internal. Give dentry's
+ * storage to target and make dentry internal
+ */
+ memcpy(dentry->d_iname, target->d_name.name,
+ target->d_name.len + 1);
+ target->d_name.name = dentry->d_name.name;
+ dentry->d_name.name = dentry->d_iname;
+ } else {
+ /*
+ * Both are internal. Just copy target to dentry
+ */
+ memcpy(dentry->d_iname, target->d_name.name,
+ target->d_name.len + 1);
+ }