- v /= 10;
- }
- /* make up a name */
- yaffs_strcpy(local_name, YAFFS_LOSTNFOUND_PREFIX);
- yaffs_strcat(local_name, x);
- yaffs_strncpy(name, local_name, buffer_size - 1);
- }
-}
-
-static void yaffs_load_name_from_oh(struct yaffs_dev *dev, YCHAR * name,
- const YCHAR * oh_name, int buff_size)
-{
-#ifdef CONFIG_YAFFS_AUTO_UNICODE
- if (dev->param.auto_unicode) {
- if (*oh_name) {
- /* It is an ASCII name, so do an ASCII to unicode conversion */
- const char *ascii_oh_name = (const char *)oh_name;
- int n = buff_size - 1;
- while (n > 0 && *ascii_oh_name) {
- *name = *ascii_oh_name;
- name++;
- ascii_oh_name++;
- n--;
- }
- } else {
- yaffs_strncpy(name, oh_name + 1, buff_size - 1);
- }
- } else {
-#else
- {
-#endif
- yaffs_strncpy(name, oh_name, buff_size - 1);
- }
-}
-
-static void yaffs_load_oh_from_name(struct yaffs_dev *dev, YCHAR * oh_name,
- const YCHAR * name)
-{
-#ifdef CONFIG_YAFFS_AUTO_UNICODE
-
- int is_ascii;
- YCHAR *w;
-
- if (dev->param.auto_unicode) {
-
- is_ascii = 1;
- w = name;
-
- /* Figure out if the name will fit in ascii character set */
- while (is_ascii && *w) {
- if ((*w) & 0xff00)
- is_ascii = 0;
- w++;
- }
-
- if (is_ascii) {
- /* It is an ASCII name, so do a unicode to ascii conversion */
- char *ascii_oh_name = (char *)oh_name;
- int n = YAFFS_MAX_NAME_LENGTH - 1;
- while (n > 0 && *name) {
- *ascii_oh_name = *name;
- name++;
- ascii_oh_name++;
- n--;
- }
- } else {
- /* It is a unicode name, so save starting at the second YCHAR */
- *oh_name = 0;
- yaffs_strncpy(oh_name + 1, name,
- YAFFS_MAX_NAME_LENGTH - 2);
- }
- } else {
-#else
- {
-#endif
- yaffs_strncpy(oh_name, name, YAFFS_MAX_NAME_LENGTH - 1);
- }
-
-}
-
-int yaffs_get_obj_name(struct yaffs_obj *obj, YCHAR * name, int buffer_size)
-{
- memset(name, 0, buffer_size * sizeof(YCHAR));
-
- yaffs_check_obj_details_loaded(obj);
-
- if (obj->obj_id == YAFFS_OBJECTID_LOSTNFOUND) {
- yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffer_size - 1);
- }
-#ifndef CONFIG_YAFFS_NO_SHORT_NAMES
- else if (obj->short_name[0]) {
- yaffs_strcpy(name, obj->short_name);
- }
-#endif
- else if (obj->hdr_chunk > 0) {
- int result;
- u8 *buffer = yaffs_get_temp_buffer(obj->my_dev, __LINE__);
-
- struct yaffs_obj_hdr *oh = (struct yaffs_obj_hdr *)buffer;
-
- memset(buffer, 0, obj->my_dev->data_bytes_per_chunk);
-
- if (obj->hdr_chunk > 0) {
- result = yaffs_rd_chunk_tags_nand(obj->my_dev,
- obj->hdr_chunk,
- buffer, NULL);
- }
- yaffs_load_name_from_oh(obj->my_dev, name, oh->name,
- buffer_size);
-
- yaffs_release_temp_buffer(obj->my_dev, buffer, __LINE__);
- }
-
- yaffs_fix_null_name(obj, name, buffer_size);
-
- return yaffs_strnlen(name, YAFFS_MAX_NAME_LENGTH);
-}
-
-int yaffs_get_obj_length(struct yaffs_obj *obj)
-{
- /* Dereference any hard linking */
- obj = yaffs_get_equivalent_obj(obj);
-
- if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
- return obj->variant.file_variant.file_size;
- if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
- if (!obj->variant.symlink_variant.alias)
- return 0;
- return yaffs_strnlen(obj->variant.symlink_variant.alias,
- YAFFS_MAX_ALIAS_LENGTH);
- } else {
- /* Only a directory should drop through to here */
- return obj->my_dev->data_bytes_per_chunk;
- }
-}
-
-int yaffs_get_obj_link_count(struct yaffs_obj *obj)
-{
- int count = 0;
- struct list_head *i;
-
- if (!obj->unlinked)
- count++; /* the object itself */
-
- list_for_each(i, &obj->hard_links)
- count++; /* add the hard links; */
-
- return count;
-}
-
-int yaffs_get_obj_inode(struct yaffs_obj *obj)
-{
- obj = yaffs_get_equivalent_obj(obj);
-
- return obj->obj_id;
-}
-
-unsigned yaffs_get_obj_type(struct yaffs_obj *obj)
-{
- obj = yaffs_get_equivalent_obj(obj);
-
- switch (obj->variant_type) {
- case YAFFS_OBJECT_TYPE_FILE:
- return DT_REG;
- break;
- case YAFFS_OBJECT_TYPE_DIRECTORY:
- return DT_DIR;
- break;
- case YAFFS_OBJECT_TYPE_SYMLINK:
- return DT_LNK;
- break;
- case YAFFS_OBJECT_TYPE_HARDLINK:
- return DT_REG;
- break;
- case YAFFS_OBJECT_TYPE_SPECIAL:
- if (S_ISFIFO(obj->yst_mode))
- return DT_FIFO;
- if (S_ISCHR(obj->yst_mode))
- return DT_CHR;
- if (S_ISBLK(obj->yst_mode))
- return DT_BLK;
- if (S_ISSOCK(obj->yst_mode))
- return DT_SOCK;
- default:
- return DT_REG;
- break;
- }
-}
-
-YCHAR *yaffs_get_symlink_alias(struct yaffs_obj *obj)
-{
- obj = yaffs_get_equivalent_obj(obj);
- if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
- return yaffs_clone_str(obj->variant.symlink_variant.alias);
- else
- return yaffs_clone_str(_Y(""));
-}
-
-static int yaffs_do_xattrib_mod(struct yaffs_obj *obj, int set,
- const YCHAR * name, const void *value, int size,
- int flags)
-{
- struct yaffs_xattr_mod xmod;
-
- int result;
-
- xmod.set = set;
- xmod.name = name;
- xmod.data = value;
- xmod.size = size;
- xmod.flags = flags;
- xmod.result = -ENOSPC;
-
- result = yaffs_update_oh(obj, NULL, 0, 0, 0, &xmod);
-
- if (result > 0)
- return xmod.result;
- else
- return -ENOSPC;
-}
-
-static int yaffs_apply_xattrib_mod(struct yaffs_obj *obj, char *buffer,
- struct yaffs_xattr_mod *xmod)
-{
- int retval = 0;
- int x_offs = sizeof(struct yaffs_obj_hdr);
- struct yaffs_dev *dev = obj->my_dev;
- int x_size = dev->data_bytes_per_chunk - sizeof(struct yaffs_obj_hdr);
-
- char *x_buffer = buffer + x_offs;
-
- if (xmod->set)
- retval =
- nval_set(x_buffer, x_size, xmod->name, xmod->data,
- xmod->size, xmod->flags);
- else
- retval = nval_del(x_buffer, x_size, xmod->name);
-
- obj->has_xattr = nval_hasvalues(x_buffer, x_size);
- obj->xattr_known = 1;
-
- xmod->result = retval;
-
- return retval;
-}
-
-static int yaffs_do_xattrib_fetch(struct yaffs_obj *obj, const YCHAR * name,
- void *value, int size)
-{
- char *buffer = NULL;
- int result;
- struct yaffs_ext_tags tags;
- struct yaffs_dev *dev = obj->my_dev;
- int x_offs = sizeof(struct yaffs_obj_hdr);
- int x_size = dev->data_bytes_per_chunk - sizeof(struct yaffs_obj_hdr);
-
- char *x_buffer;
-
- int retval = 0;
-
- if (obj->hdr_chunk < 1)
- return -ENODATA;
-
- /* If we know that the object has no xattribs then don't do all the
- * reading and parsing.
- */
- if (obj->xattr_known && !obj->has_xattr) {
- if (name)
- return -ENODATA;
- else
- return 0;