[48e3190] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2012 Julia Medvedeva
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[b1834a01] | 30 | /** @addtogroup udf
|
---|
[48e3190] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file udf_ops.c
|
---|
| 35 | * @brief Implementation of VFS operations for the UDF file system
|
---|
| 36 | * server.
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <libfs.h>
|
---|
| 40 | #include <block.h>
|
---|
| 41 | #include <ipc/services.h>
|
---|
| 42 | #include <ipc/loc.h>
|
---|
| 43 | #include <macros.h>
|
---|
| 44 | #include <async.h>
|
---|
| 45 | #include <errno.h>
|
---|
| 46 | #include <str.h>
|
---|
| 47 | #include <byteorder.h>
|
---|
| 48 | #include <adt/hash_table.h>
|
---|
| 49 | #include <adt/list.h>
|
---|
| 50 | #include <assert.h>
|
---|
| 51 | #include <fibril_synch.h>
|
---|
| 52 | #include <align.h>
|
---|
[38d150e] | 53 | #include <stdlib.h>
|
---|
[48e3190] | 54 | #include <inttypes.h>
|
---|
| 55 | #include <io/log.h>
|
---|
| 56 | #include "../../vfs/vfs.h"
|
---|
| 57 | #include "udf.h"
|
---|
| 58 | #include "udf_cksum.h"
|
---|
| 59 | #include "udf_volume.h"
|
---|
| 60 | #include "udf_idx.h"
|
---|
| 61 | #include "udf_file.h"
|
---|
| 62 | #include "udf_osta.h"
|
---|
| 63 |
|
---|
| 64 | /** List of cached free nodes. */
|
---|
| 65 | static LIST_INITIALIZE(ffn_list);
|
---|
| 66 |
|
---|
[b7fd2a0] | 67 | static errno_t udf_node_get(fs_node_t **rfn, service_id_t service_id,
|
---|
[48e3190] | 68 | fs_index_t index)
|
---|
| 69 | {
|
---|
| 70 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 71 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[48e3190] | 72 | if (rc != EOK)
|
---|
| 73 | return rc;
|
---|
[a35b458] | 74 |
|
---|
[48e3190] | 75 | udf_node_t *node;
|
---|
| 76 | rc = udf_idx_get(&node, instance, index);
|
---|
| 77 | if (rc != EOK) {
|
---|
| 78 | rc = udf_idx_add(&node, instance, index);
|
---|
| 79 | if (rc != EOK)
|
---|
| 80 | return rc;
|
---|
[a35b458] | 81 |
|
---|
[48e3190] | 82 | rc = udf_node_get_core(node);
|
---|
| 83 | if (rc != EOK) {
|
---|
| 84 | udf_idx_del(node);
|
---|
| 85 | return rc;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
[a35b458] | 88 |
|
---|
[48e3190] | 89 | *rfn = FS_NODE(node);
|
---|
| 90 | return EOK;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[b7fd2a0] | 93 | static errno_t udf_root_get(fs_node_t **rfn, service_id_t service_id)
|
---|
[48e3190] | 94 | {
|
---|
| 95 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 96 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[48e3190] | 97 | if (rc != EOK)
|
---|
| 98 | return rc;
|
---|
[a35b458] | 99 |
|
---|
[48e3190] | 100 | return udf_node_get(rfn, service_id,
|
---|
| 101 | instance->volumes[DEFAULT_VOL].root_dir);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | static service_id_t udf_service_get(fs_node_t *node)
|
---|
| 105 | {
|
---|
| 106 | return 0;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[b7fd2a0] | 109 | static errno_t udf_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
|
---|
[48e3190] | 110 | {
|
---|
| 111 | char *name = malloc(MAX_FILE_NAME_LEN + 1);
|
---|
| 112 | if (name == NULL)
|
---|
| 113 | return ENOMEM;
|
---|
[a35b458] | 114 |
|
---|
[48e3190] | 115 | block_t *block = NULL;
|
---|
| 116 | udf_file_identifier_descriptor_t *fid = NULL;
|
---|
| 117 | size_t pos = 0;
|
---|
[a35b458] | 118 |
|
---|
[48e3190] | 119 | while (udf_get_fid(&fid, &block, UDF_NODE(pfn), pos) == EOK) {
|
---|
| 120 | udf_long_ad_t long_ad = fid->icb;
|
---|
[a35b458] | 121 |
|
---|
[48e3190] | 122 | udf_to_unix_name(name, MAX_FILE_NAME_LEN,
|
---|
[c477c80] | 123 | (char *) fid->implementation_use + FLE16(fid->length_iu),
|
---|
| 124 | fid->length_file_id, &UDF_NODE(pfn)->instance->charset);
|
---|
[a35b458] | 125 |
|
---|
[0e7c3d9] | 126 | if (str_casecmp(name, component) == 0) {
|
---|
[b7fd2a0] | 127 | errno_t rc = udf_node_get(rfn, udf_service_get(pfn),
|
---|
[48e3190] | 128 | udf_long_ad_to_pos(UDF_NODE(pfn)->instance, &long_ad));
|
---|
[a35b458] | 129 |
|
---|
[48e3190] | 130 | if (block != NULL)
|
---|
| 131 | block_put(block);
|
---|
[a35b458] | 132 |
|
---|
[48e3190] | 133 | free(name);
|
---|
| 134 | return rc;
|
---|
| 135 | }
|
---|
[a35b458] | 136 |
|
---|
[48e3190] | 137 | if (block != NULL) {
|
---|
[b7fd2a0] | 138 | errno_t rc = block_put(block);
|
---|
[48e3190] | 139 | if (rc != EOK)
|
---|
| 140 | return rc;
|
---|
| 141 | }
|
---|
[a35b458] | 142 |
|
---|
[48e3190] | 143 | pos++;
|
---|
| 144 | }
|
---|
[a35b458] | 145 |
|
---|
[48e3190] | 146 | free(name);
|
---|
| 147 | return ENOENT;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[b7fd2a0] | 150 | static errno_t udf_node_open(fs_node_t *fn)
|
---|
[48e3190] | 151 | {
|
---|
| 152 | return EOK;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[b7fd2a0] | 155 | static errno_t udf_node_put(fs_node_t *fn)
|
---|
[48e3190] | 156 | {
|
---|
| 157 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 158 | if (!node)
|
---|
| 159 | return EINVAL;
|
---|
[a35b458] | 160 |
|
---|
[48e3190] | 161 | fibril_mutex_lock(&node->lock);
|
---|
| 162 | node->ref_cnt--;
|
---|
| 163 | fibril_mutex_unlock(&node->lock);
|
---|
[a35b458] | 164 |
|
---|
[48e3190] | 165 | /* Delete node from hash table and memory */
|
---|
| 166 | if (!node->ref_cnt)
|
---|
| 167 | udf_idx_del(node);
|
---|
[a35b458] | 168 |
|
---|
[48e3190] | 169 | return EOK;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[b7fd2a0] | 172 | static errno_t udf_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
|
---|
[48e3190] | 173 | {
|
---|
| 174 | return ENOTSUP;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[b7fd2a0] | 177 | static errno_t udf_destroy_node(fs_node_t *fn)
|
---|
[48e3190] | 178 | {
|
---|
| 179 | return ENOTSUP;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[b7fd2a0] | 182 | static errno_t udf_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
|
---|
[48e3190] | 183 | {
|
---|
| 184 | return ENOTSUP;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[b7fd2a0] | 187 | static errno_t udf_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
|
---|
[48e3190] | 188 | {
|
---|
| 189 | return ENOTSUP;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[b7fd2a0] | 192 | static errno_t udf_has_children(bool *has_children, fs_node_t *fn)
|
---|
[48e3190] | 193 | {
|
---|
| 194 | *has_children = true;
|
---|
| 195 | return EOK;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | static fs_index_t udf_index_get(fs_node_t *fn)
|
---|
| 199 | {
|
---|
| 200 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 201 | if (node)
|
---|
| 202 | return node->index;
|
---|
[a35b458] | 203 |
|
---|
[48e3190] | 204 | return 0;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | static aoff64_t udf_size_get(fs_node_t *fn)
|
---|
| 208 | {
|
---|
| 209 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 210 | if (node)
|
---|
| 211 | return node->data_size;
|
---|
[a35b458] | 212 |
|
---|
[48e3190] | 213 | return 0;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | static unsigned int udf_lnkcnt_get(fs_node_t *fn)
|
---|
| 217 | {
|
---|
| 218 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 219 | if (node)
|
---|
| 220 | return node->link_cnt;
|
---|
[a35b458] | 221 |
|
---|
[48e3190] | 222 | return 0;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | static bool udf_is_directory(fs_node_t *fn)
|
---|
| 226 | {
|
---|
| 227 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 228 | if (node)
|
---|
| 229 | return node->type == NODE_DIR;
|
---|
[a35b458] | 230 |
|
---|
[48e3190] | 231 | return false;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | static bool udf_is_file(fs_node_t *fn)
|
---|
| 235 | {
|
---|
| 236 | udf_node_t *node = UDF_NODE(fn);
|
---|
| 237 | if (node)
|
---|
| 238 | return node->type == NODE_FILE;
|
---|
[a35b458] | 239 |
|
---|
[48e3190] | 240 | return false;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[b7fd2a0] | 243 | static errno_t udf_size_block(service_id_t service_id, uint32_t *size)
|
---|
[52ff62d3] | 244 | {
|
---|
| 245 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 246 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[52ff62d3] | 247 | if (rc != EOK)
|
---|
| 248 | return rc;
|
---|
| 249 |
|
---|
| 250 | if (NULL == instance)
|
---|
| 251 | return ENOENT;
|
---|
[a35b458] | 252 |
|
---|
[3dd148d] | 253 | *size = instance->volumes[DEFAULT_VOL].logical_block_size;
|
---|
[a35b458] | 254 |
|
---|
[3dd148d] | 255 | return EOK;
|
---|
[52ff62d3] | 256 | }
|
---|
| 257 |
|
---|
[b7fd2a0] | 258 | static errno_t udf_total_block_count(service_id_t service_id, uint64_t *count)
|
---|
[781408e] | 259 | {
|
---|
| 260 | *count = 0;
|
---|
[a35b458] | 261 |
|
---|
[781408e] | 262 | return EOK;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[b7fd2a0] | 265 | static errno_t udf_free_block_count(service_id_t service_id, uint64_t *count)
|
---|
[781408e] | 266 | {
|
---|
| 267 | *count = 0;
|
---|
[a35b458] | 268 |
|
---|
[781408e] | 269 | return EOK;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[48e3190] | 272 | libfs_ops_t udf_libfs_ops = {
|
---|
| 273 | .root_get = udf_root_get,
|
---|
| 274 | .match = udf_match,
|
---|
| 275 | .node_get = udf_node_get,
|
---|
| 276 | .node_open = udf_node_open,
|
---|
| 277 | .node_put = udf_node_put,
|
---|
| 278 | .create = udf_create_node,
|
---|
| 279 | .destroy = udf_destroy_node,
|
---|
| 280 | .link = udf_link,
|
---|
| 281 | .unlink = udf_unlink,
|
---|
| 282 | .has_children = udf_has_children,
|
---|
| 283 | .index_get = udf_index_get,
|
---|
| 284 | .size_get = udf_size_get,
|
---|
| 285 | .lnkcnt_get = udf_lnkcnt_get,
|
---|
| 286 | .is_directory = udf_is_directory,
|
---|
| 287 | .is_file = udf_is_file,
|
---|
[52ff62d3] | 288 | .service_get = udf_service_get,
|
---|
[781408e] | 289 | .size_block = udf_size_block,
|
---|
| 290 | .total_block_count = udf_total_block_count,
|
---|
| 291 | .free_block_count = udf_free_block_count
|
---|
[48e3190] | 292 | };
|
---|
| 293 |
|
---|
[b7fd2a0] | 294 | static errno_t udf_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)
|
---|
[d2c8533] | 295 | {
|
---|
| 296 | return ENOTSUP;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[b7fd2a0] | 299 | static errno_t udf_mounted(service_id_t service_id, const char *opts,
|
---|
[4f30222] | 300 | fs_index_t *index, aoff64_t *size)
|
---|
[48e3190] | 301 | {
|
---|
| 302 | enum cache_mode cmode;
|
---|
[a35b458] | 303 |
|
---|
[48e3190] | 304 | /* Check for option enabling write through. */
|
---|
| 305 | if (str_cmp(opts, "wtcache") == 0)
|
---|
| 306 | cmode = CACHE_MODE_WT;
|
---|
| 307 | else
|
---|
| 308 | cmode = CACHE_MODE_WB;
|
---|
[a35b458] | 309 |
|
---|
[48e3190] | 310 | udf_instance_t *instance = malloc(sizeof(udf_instance_t));
|
---|
| 311 | if (!instance)
|
---|
| 312 | return ENOMEM;
|
---|
[a35b458] | 313 |
|
---|
[48e3190] | 314 | instance->sector_size = 0;
|
---|
[a35b458] | 315 |
|
---|
[48e3190] | 316 | /* Check for block size. Will be enhanced later */
|
---|
| 317 | if (str_cmp(opts, "bs=512") == 0)
|
---|
| 318 | instance->sector_size = 512;
|
---|
| 319 | else if (str_cmp(opts, "bs=1024") == 0)
|
---|
| 320 | instance->sector_size = 1024;
|
---|
| 321 | else if (str_cmp(opts, "bs=2048") == 0)
|
---|
| 322 | instance->sector_size = 2048;
|
---|
[a35b458] | 323 |
|
---|
[48e3190] | 324 | /* initialize block cache */
|
---|
[b7fd2a0] | 325 | errno_t rc = block_init(service_id, MAX_SIZE);
|
---|
[44dde42] | 326 | if (rc != EOK) {
|
---|
| 327 | free(instance);
|
---|
[48e3190] | 328 | return rc;
|
---|
[44dde42] | 329 | }
|
---|
[a35b458] | 330 |
|
---|
[48e3190] | 331 | rc = fs_instance_create(service_id, instance);
|
---|
| 332 | if (rc != EOK) {
|
---|
| 333 | free(instance);
|
---|
| 334 | block_fini(service_id);
|
---|
| 335 | return rc;
|
---|
| 336 | }
|
---|
[a35b458] | 337 |
|
---|
[48e3190] | 338 | instance->service_id = service_id;
|
---|
| 339 | instance->open_nodes_count = 0;
|
---|
[a35b458] | 340 |
|
---|
[48e3190] | 341 | /* Check Volume Recognition Sequence */
|
---|
| 342 | rc = udf_volume_recongnition(service_id);
|
---|
| 343 | if (rc != EOK) {
|
---|
[70253688] | 344 | log_msg(LOG_DEFAULT, LVL_NOTE, "VRS failed");
|
---|
[48e3190] | 345 | fs_instance_destroy(service_id);
|
---|
| 346 | free(instance);
|
---|
| 347 | block_fini(service_id);
|
---|
| 348 | return rc;
|
---|
| 349 | }
|
---|
[a35b458] | 350 |
|
---|
[48e3190] | 351 | /* Search for Anchor Volume Descriptor */
|
---|
| 352 | udf_anchor_volume_descriptor_t avd;
|
---|
| 353 | rc = udf_get_anchor_volume_descriptor(service_id, &avd);
|
---|
| 354 | if (rc != EOK) {
|
---|
[70253688] | 355 | log_msg(LOG_DEFAULT, LVL_NOTE, "Anchor read failed");
|
---|
[48e3190] | 356 | fs_instance_destroy(service_id);
|
---|
| 357 | free(instance);
|
---|
| 358 | block_fini(service_id);
|
---|
| 359 | return rc;
|
---|
| 360 | }
|
---|
[a35b458] | 361 |
|
---|
[70253688] | 362 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 363 | "Volume: Anchor volume descriptor found. Sector size=%" PRIu32,
|
---|
| 364 | instance->sector_size);
|
---|
[70253688] | 365 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 366 | "Anchor: main sequence [length=%" PRIu32 " (bytes), start=%"
|
---|
| 367 | PRIu32 " (sector)]", avd.main_extent.length,
|
---|
| 368 | avd.main_extent.location);
|
---|
[70253688] | 369 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 370 | "Anchor: reserve sequence [length=%" PRIu32 " (bytes), start=%"
|
---|
| 371 | PRIu32 " (sector)]", avd.reserve_extent.length,
|
---|
| 372 | avd.reserve_extent.location);
|
---|
[a35b458] | 373 |
|
---|
[48e3190] | 374 | /* Initialize the block cache */
|
---|
| 375 | rc = block_cache_init(service_id, instance->sector_size, 0, cmode);
|
---|
| 376 | if (rc != EOK) {
|
---|
| 377 | fs_instance_destroy(service_id);
|
---|
| 378 | free(instance);
|
---|
| 379 | block_fini(service_id);
|
---|
| 380 | return rc;
|
---|
| 381 | }
|
---|
[a35b458] | 382 |
|
---|
[48e3190] | 383 | /* Read Volume Descriptor Sequence */
|
---|
| 384 | rc = udf_read_volume_descriptor_sequence(service_id, avd.main_extent);
|
---|
| 385 | if (rc != EOK) {
|
---|
[70253688] | 386 | log_msg(LOG_DEFAULT, LVL_NOTE, "Volume Descriptor Sequence read failed");
|
---|
[48e3190] | 387 | fs_instance_destroy(service_id);
|
---|
| 388 | free(instance);
|
---|
| 389 | block_cache_fini(service_id);
|
---|
| 390 | block_fini(service_id);
|
---|
| 391 | return rc;
|
---|
| 392 | }
|
---|
[a35b458] | 393 |
|
---|
[48e3190] | 394 | fs_node_t *rfn;
|
---|
| 395 | rc = udf_node_get(&rfn, service_id, instance->volumes[DEFAULT_VOL].root_dir);
|
---|
| 396 | if (rc != EOK) {
|
---|
[70253688] | 397 | log_msg(LOG_DEFAULT, LVL_NOTE, "Can't create root node");
|
---|
[48e3190] | 398 | fs_instance_destroy(service_id);
|
---|
| 399 | free(instance);
|
---|
| 400 | block_cache_fini(service_id);
|
---|
| 401 | block_fini(service_id);
|
---|
| 402 | return rc;
|
---|
| 403 | }
|
---|
[a35b458] | 404 |
|
---|
[48e3190] | 405 | udf_node_t *node = UDF_NODE(rfn);
|
---|
| 406 | *index = instance->volumes[DEFAULT_VOL].root_dir;
|
---|
| 407 | *size = node->data_size;
|
---|
[a35b458] | 408 |
|
---|
[48e3190] | 409 | return EOK;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[b7fd2a0] | 412 | static errno_t udf_unmounted(service_id_t service_id)
|
---|
[48e3190] | 413 | {
|
---|
| 414 | fs_node_t *fn;
|
---|
[b7fd2a0] | 415 | errno_t rc = udf_root_get(&fn, service_id);
|
---|
[48e3190] | 416 | if (rc != EOK)
|
---|
| 417 | return rc;
|
---|
[a35b458] | 418 |
|
---|
[48e3190] | 419 | udf_node_t *nodep = UDF_NODE(fn);
|
---|
| 420 | udf_instance_t *instance = nodep->instance;
|
---|
[a35b458] | 421 |
|
---|
[48e3190] | 422 | /*
|
---|
| 423 | * We expect exactly two references on the root node.
|
---|
| 424 | * One for the udf_root_get() above and one created in
|
---|
| 425 | * udf_mounted().
|
---|
| 426 | */
|
---|
| 427 | if (nodep->ref_cnt != 2) {
|
---|
| 428 | udf_node_put(fn);
|
---|
| 429 | return EBUSY;
|
---|
| 430 | }
|
---|
[a35b458] | 431 |
|
---|
[48e3190] | 432 | /*
|
---|
| 433 | * Put the root node twice.
|
---|
| 434 | */
|
---|
| 435 | udf_node_put(fn);
|
---|
| 436 | udf_node_put(fn);
|
---|
[a35b458] | 437 |
|
---|
[48e3190] | 438 | fs_instance_destroy(service_id);
|
---|
| 439 | free(instance);
|
---|
| 440 | block_cache_fini(service_id);
|
---|
| 441 | block_fini(service_id);
|
---|
[a35b458] | 442 |
|
---|
[48e3190] | 443 | return EOK;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
[b7fd2a0] | 446 | static errno_t udf_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
|
---|
[48e3190] | 447 | size_t *rbytes)
|
---|
| 448 | {
|
---|
| 449 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 450 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[48e3190] | 451 | if (rc != EOK)
|
---|
| 452 | return rc;
|
---|
[a35b458] | 453 |
|
---|
[48e3190] | 454 | fs_node_t *rfn;
|
---|
| 455 | rc = udf_node_get(&rfn, service_id, index);
|
---|
| 456 | if (rc != EOK)
|
---|
| 457 | return rc;
|
---|
[a35b458] | 458 |
|
---|
[48e3190] | 459 | udf_node_t *node = UDF_NODE(rfn);
|
---|
[a35b458] | 460 |
|
---|
[984a9ba] | 461 | ipc_call_t call;
|
---|
[48e3190] | 462 | size_t len = 0;
|
---|
[984a9ba] | 463 | if (!async_data_read_receive(&call, &len)) {
|
---|
| 464 | async_answer_0(&call, EINVAL);
|
---|
[48e3190] | 465 | udf_node_put(rfn);
|
---|
| 466 | return EINVAL;
|
---|
| 467 | }
|
---|
[a35b458] | 468 |
|
---|
[48e3190] | 469 | if (node->type == NODE_FILE) {
|
---|
| 470 | if (pos >= node->data_size) {
|
---|
| 471 | *rbytes = 0;
|
---|
[984a9ba] | 472 | async_data_read_finalize(&call, NULL, 0);
|
---|
[48e3190] | 473 | udf_node_put(rfn);
|
---|
| 474 | return EOK;
|
---|
| 475 | }
|
---|
[a35b458] | 476 |
|
---|
[48e3190] | 477 | size_t read_len = 0;
|
---|
| 478 | if (node->data == NULL)
|
---|
[984a9ba] | 479 | rc = udf_read_file(&read_len, &call, node, pos, len);
|
---|
[48e3190] | 480 | else {
|
---|
| 481 | /* File in allocation descriptors area */
|
---|
| 482 | read_len = (len < node->data_size) ? len : node->data_size;
|
---|
[984a9ba] | 483 | async_data_read_finalize(&call, node->data + pos, read_len);
|
---|
[48e3190] | 484 | rc = EOK;
|
---|
| 485 | }
|
---|
[a35b458] | 486 |
|
---|
[48e3190] | 487 | *rbytes = read_len;
|
---|
| 488 | (void) udf_node_put(rfn);
|
---|
| 489 | return rc;
|
---|
| 490 | } else {
|
---|
| 491 | block_t *block = NULL;
|
---|
| 492 | udf_file_identifier_descriptor_t *fid = NULL;
|
---|
| 493 | if (udf_get_fid(&fid, &block, node, pos) == EOK) {
|
---|
| 494 | char *name = malloc(MAX_FILE_NAME_LEN + 1);
|
---|
[a35b458] | 495 |
|
---|
[48e3190] | 496 | // FIXME: Check for NULL return value
|
---|
[a35b458] | 497 |
|
---|
[48e3190] | 498 | udf_to_unix_name(name, MAX_FILE_NAME_LEN,
|
---|
[c477c80] | 499 | (char *) fid->implementation_use + FLE16(fid->length_iu),
|
---|
| 500 | fid->length_file_id, &node->instance->charset);
|
---|
[a35b458] | 501 |
|
---|
[984a9ba] | 502 | async_data_read_finalize(&call, name, str_size(name) + 1);
|
---|
[48e3190] | 503 | *rbytes = 1;
|
---|
| 504 | free(name);
|
---|
| 505 | udf_node_put(rfn);
|
---|
[a35b458] | 506 |
|
---|
[48e3190] | 507 | if (block != NULL)
|
---|
| 508 | return block_put(block);
|
---|
[a35b458] | 509 |
|
---|
[48e3190] | 510 | return EOK;
|
---|
| 511 | } else {
|
---|
| 512 | *rbytes = 0;
|
---|
| 513 | udf_node_put(rfn);
|
---|
[984a9ba] | 514 | async_answer_0(&call, ENOENT);
|
---|
[48e3190] | 515 | return ENOENT;
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
| 518 | }
|
---|
| 519 |
|
---|
[b7fd2a0] | 520 | static errno_t udf_close(service_id_t service_id, fs_index_t index)
|
---|
[48e3190] | 521 | {
|
---|
| 522 | return EOK;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[b7fd2a0] | 525 | static errno_t udf_sync(service_id_t service_id, fs_index_t index)
|
---|
[48e3190] | 526 | {
|
---|
| 527 | return ENOTSUP;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
[b7fd2a0] | 530 | static errno_t udf_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
|
---|
[48e3190] | 531 | size_t *wbytes, aoff64_t *nsize)
|
---|
| 532 | {
|
---|
| 533 | return ENOTSUP;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
[b7fd2a0] | 536 | static errno_t udf_truncate(service_id_t service_id, fs_index_t index,
|
---|
[48e3190] | 537 | aoff64_t size)
|
---|
| 538 | {
|
---|
| 539 | return ENOTSUP;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[b7fd2a0] | 542 | static errno_t udf_destroy(service_id_t service_id, fs_index_t index)
|
---|
[48e3190] | 543 | {
|
---|
| 544 | return ENOTSUP;
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | vfs_out_ops_t udf_ops = {
|
---|
[d2c8533] | 548 | .fsprobe = udf_fsprobe,
|
---|
[48e3190] | 549 | .mounted = udf_mounted,
|
---|
| 550 | .unmounted = udf_unmounted,
|
---|
| 551 | .read = udf_read,
|
---|
| 552 | .write = udf_write,
|
---|
| 553 | .truncate = udf_truncate,
|
---|
| 554 | .close = udf_close,
|
---|
| 555 | .destroy = udf_destroy,
|
---|
| 556 | .sync = udf_sync
|
---|
| 557 | };
|
---|
| 558 |
|
---|
| 559 | /**
|
---|
| 560 | * @}
|
---|
| 561 | */
|
---|