status_t dosfs_read_attr_stat(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct stat *stat) { nspace *vol = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; DPRINTF(0, ("dosfs_read_attr_stat\n")); if (_cookie != &kBeOSTypeCookie) return ENOENT; LOCK_VOL(vol); if (node->mime == NULL) { UNLOCK_VOL(vol); return ENOENT; } stat->st_type = MIME_STRING_TYPE; stat->st_size = strlen(node->mime) + 1; UNLOCK_VOL(vol); return 0; }
status_t fs_closedir(fs_volume *_vol, fs_vnode *_node, void *cookie) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_node->private_node; int result = B_NO_ERROR; ntfs_inode *ni = NULL; LOCK_VOL(ns); TRACE("fs_closedir - ENTER\n"); ni = ntfs_inode_open(ns->ntvol, node->vnid); if (ni == NULL) { result = ENOENT; goto exit; } fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_ATIME); exit: if (ni) ntfs_inode_close(ni); TRACE("fs_closedir - EXIT\n"); UNLOCK_VOL(ns); return result; }
status_t fake_read_attrib_stat(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct stat *stat) { nspace *ns = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; int result = B_NO_ERROR; LOCK_VOL(ns); TRACE("fake_read_attr_stat - ENTER\n"); if (_cookie != &kSetTypeCookie) { result = ENOENT; goto exit; } stat->st_type = MIME_STRING_TYPE; if (node->mime == NULL) stat->st_size = 0; else stat->st_size = strlen(node->mime) + 1; exit: TRACE("fake_read_attrib_stat - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fs_read_attrib(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos, void *buffer, size_t *len) { nspace *ns = (nspace *)_vol->private_volume; //vnode *node = (vnode *)_node->private_node; attrcookie *cookie = (attrcookie *)_cookie; ntfs_inode *ni = cookie->inode; ntfs_attr *na = cookie->stream; size_t size = *len; int total = 0; status_t result = B_NO_ERROR; if (pos < 0) { *len = 0; return EINVAL; } LOCK_VOL(ns); TRACE("%s - ENTER\n", __FUNCTION__); // it is a named stream if (na) { if (pos + size > na->data_size) size = na->data_size - pos; while (size) { off_t bytesRead = ntfs_attr_pread(na, pos, size, buffer); if (bytesRead < (s64)size) { ntfs_log_error("ntfs_attr_pread returned less bytes than " "requested.\n"); } if (bytesRead <= 0) { *len = 0; result = EINVAL; goto exit; } size -= bytesRead; pos += bytesRead; total += bytesRead; } *len = total; } else { *len = 0; result = ENOENT; // TODO } fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_ATIME); // XXX needed ? exit: TRACE("%s - EXIT, result is %s\n", __FUNCTION__, strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct dirent *entry, size_t bufsize, uint32 *num) { nspace *ns = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; int32 *cookie = (int32 *)_cookie; LOCK_VOL(ns); TRACE("fake_read_attrdir - ENTER\n"); *num = 0; if ((*cookie == kOpenTypeCookie) && (node->mime)) { *num = 1; entry->d_ino = node->vnid; entry->d_dev = ns->id; entry->d_reclen = sizeof(struct dirent) + strlen(kAttrMimeTypeName); strcpy(entry->d_name, kAttrMimeTypeName); } *cookie = kCloseTypeCookie; TRACE("fake_read_attrdir - EXIT\n"); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fs_read_attrib_stat(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct stat *stat) { nspace *ns = (nspace *)_vol->private_volume; //vnode *node = (vnode *)_node->private_node; attrcookie *cookie = (attrcookie *)_cookie; //ntfs_inode *ni = cookie->inode; ntfs_attr *na = cookie->stream; //status_t result = B_NO_ERROR; LOCK_VOL(ns); //ERRPRINT("%s - ENTER\n", __FUNCTION__); stat->st_type = B_XATTR_TYPE; stat->st_size = na ? na->data_size : 0; //exit: UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t dosfs_read_attrdir(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct dirent *entry, size_t bufsize, uint32 *num) { nspace *vol = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; int32 *cookie = (int32 *)_cookie; TOUCH(bufsize); DPRINTF(0, ("dosfs_read_attrdir called\n")); *num = 0; LOCK_VOL(vol); if ((*cookie == 0) && (node->mime)) { *num = 1; entry->d_ino = node->vnid; entry->d_dev = vol->id; entry->d_reclen = 10; strcpy(entry->d_name, "BEOS:TYPE"); } *cookie = 1; UNLOCK_VOL(vol); return 0; }
status_t fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *ns = (nspace *)_vol->private_volume; int result = B_NO_ERROR; LOCK_VOL(ns); TRACE("fake_free_attrib_dir_cookie - ENTER\n"); if (_cookie == NULL) { TRACE("fake_free_attrib_dir_cookie - error:called with null cookie\n"); result = EINVAL; goto exit; } *(int32 *)_cookie = kFreeTypeCookie; free(_cookie); exit: TRACE("fake_free_attrib_dir_cookie - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fs_rewinddir(fs_volume *_vol, fs_vnode *vnode, void *_cookie) { nspace *ns = (nspace*)_vol->private_volume; dircookie *cookie = (dircookie*)_cookie; int result = EINVAL; LOCK_VOL(ns); TRACE("fs_rewinddir - ENTER\n"); if (cookie != NULL) { cookie->pos = 0; cookie->ino = 0; cookie->readed = 0; cookie->last = 0; cookie->name[0] = 0; result = B_NO_ERROR; } TRACE("fs_rewinddir - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fake_open_attrib_dir(fs_volume *_vol, fs_vnode *_node, void **_cookie) { nspace *ns = (nspace *)_vol->private_volume; int result = B_NO_ERROR; TRACE("fake_open_attrdir - ENTER\n"); LOCK_VOL(ns); if ((*_cookie = malloc(sizeof(uint32))) == NULL) { result = ENOMEM; goto exit; } *(int32 *)(*_cookie) = kOpenTypeCookie; exit: TRACE("fake_open_attrdir - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fs_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *ns = (nspace*)_vol->private_volume; attrdircookie *cookie = (attrdircookie *)_cookie; status_t result = B_NO_ERROR; TRACE("%s - ENTER\n", __FUNCTION__); LOCK_VOL(ns); if (cookie->ctx) ntfs_attr_put_search_ctx(cookie->ctx); cookie->ctx = ntfs_attr_get_search_ctx(cookie->inode, NULL); if (cookie->ctx == NULL) { result = errno; //goto exit; } //exit: TRACE("%s - EXIT, result is %s\n", __FUNCTION__, strerror(result)); UNLOCK_VOL(ns); return result; }
status_t dosfs_open_attrdir(fs_volume *_vol, fs_vnode *_node, void **_cookie) { nspace *vol = (nspace *)_vol->private_volume; TOUCH(_node); DPRINTF(0, ("dosfs_open_attrdir called\n")); LOCK_VOL(vol); if ((*_cookie = malloc(sizeof(uint32))) == NULL) { UNLOCK_VOL(vol); return ENOMEM; } *(int32 *)(*_cookie) = 0; UNLOCK_VOL(vol); return 0; }
status_t fs_open_attrib_dir(fs_volume *_vol, fs_vnode *_node, void **_cookie) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_node->private_node; attrdircookie *cookie = NULL; ntfs_inode *ni = NULL; ntfs_attr_search_ctx *ctx = NULL; status_t result = B_NO_ERROR; TRACE("%s - ENTER\n", __FUNCTION__); LOCK_VOL(ns); ni = ntfs_inode_open(ns->ntvol, node->vnid); if (ni == NULL) { result = errno; goto exit; } ctx = ntfs_attr_get_search_ctx(ni, NULL); if (ctx == NULL) { result = errno; goto exit; } cookie = (attrdircookie*)ntfs_calloc(sizeof(attrdircookie)); if (cookie == NULL) { result = ENOMEM; goto exit; } cookie->inode = ni; cookie->ctx = ctx; ni = NULL; ctx = NULL; *_cookie = cookie; exit: if (ctx) ntfs_attr_put_search_ctx(ctx); if (ni) ntfs_inode_close(ni); TRACE("%s - EXIT, result is %s\n", __FUNCTION__, strerror(result)); UNLOCK_VOL(ns); return result; }
status_t dosfs_open_attr(fs_volume *_vol, fs_vnode *_node, const char *name, int openMode, void **_cookie) { nspace *vol = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; if (strcmp(name, "BEOS:TYPE")) return ENOENT; LOCK_VOL(vol); if (node->mime == NULL) { UNLOCK_VOL(vol); return ENOENT; } UNLOCK_VOL(vol); *_cookie = &kBeOSTypeCookie; return B_OK; }
status_t dosfs_read_attr(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos, void *buffer, size_t *_length) { nspace *vol = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; ssize_t length; DPRINTF(0, ("dosfs_read_attr\n")); if (_cookie != &kBeOSTypeCookie) return ENOENT; LOCK_VOL(vol); if (node->mime == NULL) { UNLOCK_VOL(vol); return ENOENT; } if ((pos < 0) || (pos > strlen(node->mime))) { UNLOCK_VOL(vol); return EINVAL; } length = user_strlcpy(buffer, node->mime + pos, *_length); if (length < B_OK) { UNLOCK_VOL(vol); return B_BAD_ADDRESS; } if (length < *_length) *_length = length + 1; UNLOCK_VOL(vol); return 0; }
status_t fs_free_dircookie(fs_volume *_vol, fs_vnode *vnode, void *cookie) { nspace *ns = (nspace*)_vol->private_volume; LOCK_VOL(ns); TRACE("fs_free_dircookie - ENTER\n"); if (cookie != NULL) free(cookie); TRACE("fs_free_dircookie - EXIT\n"); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fs_free_attrib_cookie(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *ns = (nspace*)_vol->private_volume; attrcookie *cookie = (attrcookie *)_cookie; LOCK_VOL(ns); if (cookie->uname != NULL) free(cookie->uname); UNLOCK_VOL(ns); free(cookie); return B_NO_ERROR; }
status_t fs_opendir(fs_volume *_vol, fs_vnode *_node, void** _cookie) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_node->private_node; dircookie *cookie = NULL; int result = B_NO_ERROR; ntfs_inode *ni = NULL; LOCK_VOL(ns); TRACE("fs_opendir - ENTER\n"); ni = ntfs_inode_open(ns->ntvol, node->vnid); if (ni == NULL) { result = ENOENT; goto exit; } if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { result = EMFILE; goto exit; } cookie = (dircookie*)ntfs_calloc(sizeof(dircookie)); if (cookie != NULL) { cookie->pos = 0; cookie->ino = 0; cookie->readed = 0; cookie->last = 0; cookie->name[0] = 0; cookie->show_sys_files = ns->show_sys_files; *_cookie = (void*)cookie; } else result = ENOMEM; exit: if (ni) ntfs_inode_close(ni); TRACE("fs_opendir - EXIT\n"); UNLOCK_VOL(ns); return result; }
status_t dosfs_close_attrdir(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *vol = (nspace *)_vol->private_volume; TOUCH(_node); DPRINTF(0, ("dosfs_close_attrdir called\n")); LOCK_VOL(vol); *(int32 *)_cookie = 1; UNLOCK_VOL(vol); return 0; }
status_t fake_close_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *ns = (nspace *)_vol->private_volume; TRACE("fake_close_attrdir - ENTER\n"); LOCK_VOL(ns); *(int32 *)_cookie = kCloseTypeCookie; TRACE("fake_close_attrdir - EXIT\n"); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos,void *buffer, size_t *_length) { nspace *ns = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; int result = B_NO_ERROR; ssize_t length; LOCK_VOL(ns); TRACE("fake_read_attr - ENTER\n"); if (_cookie != &kSetTypeCookie) { result = ENOENT; goto exit; } if (node->mime == NULL) { result = ENOENT; goto exit; } if ((pos < 0) || (pos > strlen(node->mime))) { result = EINVAL; goto exit; } length = user_strlcpy(buffer, node->mime + pos, *_length); if (length < B_OK) { result = B_BAD_ADDRESS; goto exit; } if (length < *_length) *_length = length + 1; exit: TRACE("fake_read_attr - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fs_free_attrib_cookie(fs_volume *_vol, fs_vnode *_node, void *_cookie) { nspace *ns = (nspace*)_vol->private_volume; attrcookie *cookie = (attrcookie *)_cookie; LOCK_VOL(ns); if (cookie->stream) ntfs_attr_close(cookie->stream); if (cookie->inode) ntfs_inode_close(cookie->inode); UNLOCK_VOL(ns); free(cookie); return B_NO_ERROR; }
status_t fake_create_attrib(fs_volume *_vol, fs_vnode *_node, const char* name, uint32 type, int openMode, void** _cookie) { nspace *ns = (nspace *)_vol->private_volume; LOCK_VOL(ns); TRACE("fake_create_attrib - ENTER (name = [%s])\n",name); if (strcmp(name, kAttrMimeTypeName) == 0) *_cookie = &kSetTypeCookie; TRACE("fake_create_attrib - EXIT\n"); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fs_write_vnode(fs_volume *_vol, fs_vnode *_node, bool reenter) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_node->private_node; status_t result = B_NO_ERROR; if (!reenter) LOCK_VOL(ns); ERRPRINT("fs_write_vnode - ENTER (%Ld)\n", node->vnid); free(node); ERRPRINT("fs_write_vnode - EXIT\n"); if (!reenter) UNLOCK_VOL(ns); return result; }
status_t fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos,void *buffer, size_t *_length) { nspace *ns = (nspace *)_vol->private_volume; vnode *node = (vnode *)_node->private_node; int result = B_NO_ERROR; LOCK_VOL(ns); TRACE("fake_read_attr - ENTER\n"); if (_cookie != &kSetTypeCookie) { result = ENOENT; goto exit; } if (node->mime == NULL) { result = ENOENT; goto exit; } if ((pos < 0) || (pos > strlen(node->mime))) { result = EINVAL; goto exit; } strncpy(buffer, node->mime + pos, *_length - 1); ((char *)buffer)[*_length - 1] = 0; *_length = strlen(buffer) + 1; exit: TRACE("fake_read_attr - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fs_rfsstat(fs_volume *_vol, struct fs_info *fss) { nspace *ns = (nspace*)_vol->private_volume; int i; LOCK_VOL(ns); ERRPRINT("fs_rfsstat - ENTER\n"); ntfs_calc_free_space(ns); fss->dev = ns->id; fss->root = FILE_root; fss->flags = B_FS_IS_PERSISTENT | B_FS_HAS_MIME | B_FS_HAS_ATTR | ns->flags; fss->block_size = ns->ntvol->cluster_size; fss->io_size = 65536; fss->total_blocks = ns->ntvol->nr_clusters; fss->free_blocks = ns->free_clusters; strncpy(fss->device_name, ns->devicePath, sizeof(fss->device_name)); strncpy(fss->volume_name, ns->ntvol->vol_name, sizeof(fss->volume_name)); for (i = strlen(fss->volume_name) - 1; i >=0 ; i--) { if (fss->volume_name[i] != ' ') break; } if (i < 0) strcpy(fss->volume_name, "NTFS Untitled"); else fss->volume_name[i + 1] = 0; strcpy(fss->fsh_name, "NTFS"); ERRPRINT("fs_rfsstat - EXIT\n"); UNLOCK_VOL(ns); return B_NO_ERROR; }
status_t fs_remove_vnode(fs_volume *_vol, fs_vnode *_node, bool reenter) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_node->private_node; status_t result = B_NO_ERROR; // TODO: this does not look right! The space if the node must be freed *here* if (!reenter) LOCK_VOL(ns); ERRPRINT("fs_remove_vnode - ENTER (%Ld)\n", node->vnid); free(node); ERRPRINT("fs_remove_vnode - EXIT, result is %s\n", strerror(result)); if (!reenter) UNLOCK_VOL(ns); return result; }
status_t fake_open_attrib(fs_volume *_vol, fs_vnode *_node, const char *name, int openMode, void **_cookie) { nspace *ns = (nspace *)_vol->private_volume; status_t result = B_NO_ERROR; LOCK_VOL(ns); TRACE("fake_open_attrib - ENTER (name = [%s])\n",name); if (strcmp(name, kAttrMimeTypeName) == 0) *_cookie = &kSetTypeCookie; else result = ENOENT; TRACE("fake_open_attrib - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); return result; }
status_t fs_get_vnode_name(fs_volume *_vol, fs_vnode *_vnode, char *buffer, size_t bufferSize) { nspace *ns = (nspace*)_vol->private_volume; vnode *node = (vnode*)_vnode->private_node; ntfs_inode *ni = NULL; status_t result = B_NO_ERROR; char path[MAX_PATH]; char *name; LOCK_VOL(ns); ni = ntfs_inode_open(ns->ntvol, node->vnid); if (ni == NULL) { result = ENOENT; goto exit; } if (utils_inode_get_name(ni, path, MAX_PATH) == 0) { result = EINVAL; goto exit; } name = strrchr(path, '/'); name++; strlcpy(buffer, name, bufferSize); exit: if (ni) ntfs_inode_close(ni); UNLOCK_VOL(ns); return result; }
status_t fs_wfsstat(fs_volume *_vol, const struct fs_info *fss, uint32 mask) { nspace* ns = (nspace*)_vol->private_volume; status_t result = B_NO_ERROR; if (ns->flags & B_FS_IS_READONLY) { ERRPRINT("ntfs is read-only\n"); return EROFS; } LOCK_VOL(ns); if (mask & FS_WRITE_FSINFO_NAME) { result = ntfs_change_label(ns->ntvol, (char*)fss->volume_name); goto exit; } exit: UNLOCK_VOL(ns); return result; }