2002-04-14 16:52:14 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* udf_vnops.c */
|
|
|
|
/* Take care of the vnode side of things */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/bio.h>
|
2005-03-14 12:29:39 +00:00
|
|
|
#include <sys/conf.h>
|
2002-04-14 16:52:14 +00:00
|
|
|
#include <sys/buf.h>
|
2003-11-05 06:56:08 +00:00
|
|
|
#include <sys/iconv.h>
|
2002-04-14 16:52:14 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/unistd.h>
|
2004-06-23 19:36:09 +00:00
|
|
|
#include <sys/endian.h>
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
#include <vm/uma.h>
|
|
|
|
|
|
|
|
#include <fs/udf/ecma167-udf.h>
|
|
|
|
#include <fs/udf/osta.h>
|
|
|
|
#include <fs/udf/udf.h>
|
2003-11-05 06:56:08 +00:00
|
|
|
#include <fs/udf/udf_mount.h>
|
|
|
|
|
|
|
|
extern struct iconv_functions *udf_iconv;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_access_t udf_access;
|
|
|
|
static vop_getattr_t udf_getattr;
|
2006-12-23 18:53:22 +00:00
|
|
|
static vop_open_t udf_open;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_ioctl_t udf_ioctl;
|
|
|
|
static vop_pathconf_t udf_pathconf;
|
2009-02-06 20:09:14 +00:00
|
|
|
static vop_print_t udf_print;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_read_t udf_read;
|
|
|
|
static vop_readdir_t udf_readdir;
|
|
|
|
static vop_readlink_t udf_readlink;
|
2009-02-06 20:09:14 +00:00
|
|
|
static vop_setattr_t udf_setattr;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_strategy_t udf_strategy;
|
|
|
|
static vop_bmap_t udf_bmap;
|
|
|
|
static vop_cachedlookup_t udf_lookup;
|
|
|
|
static vop_reclaim_t udf_reclaim;
|
2007-02-15 22:08:35 +00:00
|
|
|
static vop_vptofh_t udf_vptofh;
|
2005-01-12 06:42:13 +00:00
|
|
|
static int udf_readatoffset(struct udf_node *node, int *size, off_t offset,
|
|
|
|
struct buf **bp, uint8_t **data);
|
|
|
|
static int udf_bmap_internal(struct udf_node *node, off_t offset,
|
|
|
|
daddr_t *sector, uint32_t *max_size);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
static struct vop_vector udf_vnodeops = {
|
|
|
|
.vop_default = &default_vnodeops,
|
2005-01-13 18:59:48 +00:00
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_access = udf_access,
|
|
|
|
.vop_bmap = udf_bmap,
|
|
|
|
.vop_cachedlookup = udf_lookup,
|
|
|
|
.vop_getattr = udf_getattr,
|
|
|
|
.vop_ioctl = udf_ioctl,
|
|
|
|
.vop_lookup = vfs_cache_lookup,
|
2006-12-23 18:53:22 +00:00
|
|
|
.vop_open = udf_open,
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_pathconf = udf_pathconf,
|
2009-02-06 20:09:14 +00:00
|
|
|
.vop_print = udf_print,
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_read = udf_read,
|
|
|
|
.vop_readdir = udf_readdir,
|
|
|
|
.vop_readlink = udf_readlink,
|
|
|
|
.vop_reclaim = udf_reclaim,
|
2009-02-06 20:09:14 +00:00
|
|
|
.vop_setattr = udf_setattr,
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_strategy = udf_strategy,
|
2007-02-15 22:08:35 +00:00
|
|
|
.vop_vptofh = udf_vptofh,
|
2002-04-14 16:52:14 +00:00
|
|
|
};
|
|
|
|
|
2009-02-06 20:09:14 +00:00
|
|
|
struct vop_vector udf_fifoops = {
|
|
|
|
.vop_default = &fifo_specops,
|
|
|
|
.vop_access = udf_access,
|
|
|
|
.vop_getattr = udf_getattr,
|
|
|
|
.vop_print = udf_print,
|
|
|
|
.vop_reclaim = udf_reclaim,
|
|
|
|
.vop_setattr = udf_setattr,
|
|
|
|
.vop_vptofh = udf_vptofh,
|
|
|
|
};
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_UDFFID, "udf_fid", "UDF FileId structure");
|
|
|
|
static MALLOC_DEFINE(M_UDFDS, "udf_ds", "UDF Dirstream structure");
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 03:50:06 +00:00
|
|
|
#define UDF_INVALID_BMAP -1
|
2002-08-02 06:22:20 +00:00
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
int
|
|
|
|
udf_allocv(struct mount *mp, struct vnode **vpp, struct thread *td)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct vnode *vp;
|
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
error = getnewvnode("udf", mp, &udf_vnodeops, &vp);
|
2002-04-14 16:52:14 +00:00
|
|
|
if (error) {
|
|
|
|
printf("udf_allocv: failed to allocate new vnode\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert file entry permission (5 bits per owner/group/user) to a mode_t */
|
|
|
|
static mode_t
|
|
|
|
udf_permtomode(struct udf_node *node)
|
|
|
|
{
|
2002-04-15 19:49:15 +00:00
|
|
|
uint32_t perm;
|
2004-06-23 21:49:03 +00:00
|
|
|
uint16_t flags;
|
2002-04-14 16:52:14 +00:00
|
|
|
mode_t mode;
|
|
|
|
|
2004-06-23 21:49:03 +00:00
|
|
|
perm = le32toh(node->fentry->perm);
|
|
|
|
flags = le16toh(node->fentry->icbtag.flags);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
mode = perm & UDF_FENTRY_PERM_USER_MASK;
|
|
|
|
mode |= ((perm & UDF_FENTRY_PERM_GRP_MASK) >> 2);
|
|
|
|
mode |= ((perm & UDF_FENTRY_PERM_OWNER_MASK) >> 4);
|
|
|
|
mode |= ((flags & UDF_ICB_TAG_FLAGS_STICKY) << 4);
|
|
|
|
mode |= ((flags & UDF_ICB_TAG_FLAGS_SETGID) << 6);
|
|
|
|
mode |= ((flags & UDF_ICB_TAG_FLAGS_SETUID) << 8);
|
|
|
|
|
|
|
|
return (mode);
|
|
|
|
}
|
2003-03-02 15:56:49 +00:00
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
static int
|
|
|
|
udf_access(struct vop_access_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct udf_node *node;
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t accmode;
|
|
|
|
mode_t mode;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
vp = a->a_vp;
|
|
|
|
node = VTON(vp);
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode = a->a_accmode;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2008-10-28 13:44:11 +00:00
|
|
|
if (accmode & VWRITE) {
|
2002-04-14 16:52:14 +00:00
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
case VLNK:
|
|
|
|
case VREG:
|
|
|
|
return (EROFS);
|
|
|
|
/* NOT REACHED */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = udf_permtomode(node);
|
|
|
|
|
|
|
|
return (vaccess(vp->v_type, mode, node->fentry->uid, node->fentry->gid,
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode, a->a_cred, NULL));
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2006-12-23 18:53:22 +00:00
|
|
|
static int
|
|
|
|
udf_open(struct vop_open_args *ap) {
|
|
|
|
struct udf_node *np = VTON(ap->a_vp);
|
|
|
|
off_t fsize;
|
|
|
|
|
|
|
|
fsize = le64toh(np->fentry->inf_len);
|
|
|
|
vnode_create_vobject(ap->a_vp, fsize, ap->a_td);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-16 22:31:17 +00:00
|
|
|
static const int mon_lens[2][12] = {
|
|
|
|
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
|
|
|
|
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
|
2002-04-14 16:52:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_isaleapyear(int year)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = (year % 4) ? 0 : 1;
|
|
|
|
i &= (year % 100) ? 1 : 0;
|
|
|
|
i |= (year % 400) ? 0 : 1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timezone calculation compliments of Julian Elischer <julian@elischer.org>.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
udf_timetotimespec(struct timestamp *time, struct timespec *t)
|
|
|
|
{
|
2008-05-16 22:31:17 +00:00
|
|
|
int i, lpyear, daysinyear, year, startyear;
|
2002-04-14 16:52:14 +00:00
|
|
|
union {
|
2002-04-15 19:49:15 +00:00
|
|
|
uint16_t u_tz_offset;
|
2002-04-14 16:52:14 +00:00
|
|
|
int16_t s_tz_offset;
|
|
|
|
} tz;
|
|
|
|
|
2008-05-16 22:31:17 +00:00
|
|
|
/*
|
|
|
|
* DirectCD seems to like using bogus year values.
|
|
|
|
* Don't trust time->month as it will be used for an array index.
|
|
|
|
*/
|
2004-06-23 21:49:03 +00:00
|
|
|
year = le16toh(time->year);
|
2008-05-16 22:31:17 +00:00
|
|
|
if (year < 1970 || time->month < 1 || time->month > 12) {
|
2002-04-14 16:52:14 +00:00
|
|
|
t->tv_sec = 0;
|
2008-05-16 22:31:17 +00:00
|
|
|
t->tv_nsec = 0;
|
2002-04-14 16:52:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the time and day */
|
|
|
|
t->tv_sec = time->second;
|
|
|
|
t->tv_sec += time->minute * 60;
|
|
|
|
t->tv_sec += time->hour * 3600;
|
2008-05-16 22:31:17 +00:00
|
|
|
t->tv_sec += (time->day - 1) * 3600 * 24;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2005-05-11 21:10:35 +00:00
|
|
|
/* Calculate the month */
|
2004-06-23 21:49:03 +00:00
|
|
|
lpyear = udf_isaleapyear(year);
|
2008-05-16 22:31:17 +00:00
|
|
|
t->tv_sec += mon_lens[lpyear][time->month - 1] * 3600 * 24;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
/* Speed up the calculation */
|
2008-05-16 22:31:17 +00:00
|
|
|
startyear = 1970;
|
|
|
|
if (year > 2009) {
|
|
|
|
t->tv_sec += 1262304000;
|
|
|
|
startyear += 40;
|
|
|
|
} else if (year > 1999) {
|
|
|
|
t->tv_sec += 946684800;
|
|
|
|
startyear += 30;
|
|
|
|
} else if (year > 1989) {
|
|
|
|
t->tv_sec += 631152000;
|
|
|
|
startyear += 20;
|
|
|
|
} else if (year > 1979) {
|
2002-04-14 16:52:14 +00:00
|
|
|
t->tv_sec += 315532800;
|
2008-05-16 22:31:17 +00:00
|
|
|
startyear += 10;
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-16 22:31:17 +00:00
|
|
|
daysinyear = (year - startyear) * 365;
|
|
|
|
for (i = startyear; i < year; i++)
|
|
|
|
daysinyear += udf_isaleapyear(i);
|
|
|
|
t->tv_sec += daysinyear * 3600 * 24;
|
|
|
|
|
|
|
|
/* Calculate microseconds */
|
|
|
|
t->tv_nsec = time->centisec * 10000 + time->hund_usec * 100 +
|
|
|
|
time->usec;
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
/*
|
|
|
|
* Calculate the time zone. The timezone is 12 bit signed 2's
|
2005-05-11 21:10:35 +00:00
|
|
|
* complement, so we gotta do some extra magic to handle it right.
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
2004-06-23 21:49:03 +00:00
|
|
|
tz.u_tz_offset = le16toh(time->type_tz);
|
2002-04-14 16:52:14 +00:00
|
|
|
tz.u_tz_offset &= 0x0fff;
|
|
|
|
if (tz.u_tz_offset & 0x0800)
|
|
|
|
tz.u_tz_offset |= 0xf000; /* extend the sign to 16 bits */
|
2008-05-16 22:31:17 +00:00
|
|
|
if ((le16toh(time->type_tz) & 0x1000) && (tz.s_tz_offset != -2047))
|
2002-04-14 16:52:14 +00:00
|
|
|
t->tv_sec -= tz.s_tz_offset * 60;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_getattr(struct vop_getattr_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct udf_node *node;
|
|
|
|
struct vattr *vap;
|
|
|
|
struct file_entry *fentry;
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
|
|
|
|
vp = a->a_vp;
|
|
|
|
vap = a->a_vap;
|
|
|
|
node = VTON(vp);
|
|
|
|
fentry = node->fentry;
|
|
|
|
|
2005-03-17 15:15:29 +00:00
|
|
|
vap->va_fsid = dev2udev(node->udfmp->im_dev);
|
2002-04-14 16:52:14 +00:00
|
|
|
vap->va_fileid = node->hash_id;
|
|
|
|
vap->va_mode = udf_permtomode(node);
|
2004-06-23 21:49:03 +00:00
|
|
|
vap->va_nlink = le16toh(fentry->link_cnt);
|
2002-04-14 16:52:14 +00:00
|
|
|
/*
|
|
|
|
* XXX The spec says that -1 is valid for uid/gid and indicates an
|
|
|
|
* invalid uid/gid. How should this be represented?
|
|
|
|
*/
|
2004-06-23 21:49:03 +00:00
|
|
|
vap->va_uid = (le32toh(fentry->uid) == -1) ? 0 : le32toh(fentry->uid);
|
|
|
|
vap->va_gid = (le32toh(fentry->gid) == -1) ? 0 : le32toh(fentry->gid);
|
2002-04-14 16:52:14 +00:00
|
|
|
udf_timetotimespec(&fentry->atime, &vap->va_atime);
|
|
|
|
udf_timetotimespec(&fentry->mtime, &vap->va_mtime);
|
|
|
|
vap->va_ctime = vap->va_mtime; /* XXX Stored as an Extended Attribute */
|
2008-09-20 19:49:15 +00:00
|
|
|
vap->va_rdev = NODEV;
|
2002-04-14 16:52:14 +00:00
|
|
|
if (vp->v_type & VDIR) {
|
|
|
|
/*
|
|
|
|
* Directories that are recorded within their ICB will show
|
|
|
|
* as having 0 blocks recorded. Since tradition dictates
|
|
|
|
* that directories consume at least one logical block,
|
|
|
|
* make it appear so.
|
|
|
|
*/
|
|
|
|
if (fentry->logblks_rec != 0) {
|
2004-06-23 21:49:03 +00:00
|
|
|
vap->va_size =
|
|
|
|
le64toh(fentry->logblks_rec) * node->udfmp->bsize;
|
2002-04-14 16:52:14 +00:00
|
|
|
} else {
|
|
|
|
vap->va_size = node->udfmp->bsize;
|
|
|
|
}
|
|
|
|
} else {
|
2004-06-23 21:49:03 +00:00
|
|
|
vap->va_size = le64toh(fentry->inf_len);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_gen = 1;
|
|
|
|
vap->va_blocksize = node->udfmp->bsize;
|
2004-06-23 21:49:03 +00:00
|
|
|
vap->va_bytes = le64toh(fentry->inf_len);
|
2002-04-14 16:52:14 +00:00
|
|
|
vap->va_type = vp->v_type;
|
|
|
|
vap->va_filerev = 0; /* XXX */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-02-06 20:09:14 +00:00
|
|
|
static int
|
|
|
|
udf_setattr(struct vop_setattr_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr *vap;
|
|
|
|
|
|
|
|
vp = a->a_vp;
|
|
|
|
vap = a->a_vap;
|
|
|
|
if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
|
|
|
|
vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
|
|
|
|
vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
|
|
|
|
return (EROFS);
|
|
|
|
if (vap->va_size != (u_quad_t)VNOVAL) {
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
return (EISDIR);
|
|
|
|
case VLNK:
|
|
|
|
case VREG:
|
|
|
|
return (EROFS);
|
|
|
|
case VCHR:
|
|
|
|
case VBLK:
|
|
|
|
case VSOCK:
|
|
|
|
case VFIFO:
|
|
|
|
case VNON:
|
|
|
|
case VBAD:
|
|
|
|
case VMARKER:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
/*
|
2004-06-23 21:49:03 +00:00
|
|
|
* File specific ioctls.
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
udf_ioctl(struct vop_ioctl_args *a)
|
|
|
|
{
|
2004-03-03 07:43:34 +00:00
|
|
|
printf("%s called\n", __func__);
|
2002-09-26 14:08:37 +00:00
|
|
|
return (ENOTTY);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I'm not sure that this has much value in a read-only filesystem, but
|
|
|
|
* cd9660 has it too.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
udf_pathconf(struct vop_pathconf_args *a)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (a->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*a->a_retval = 65535;
|
|
|
|
return (0);
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*a->a_retval = NAME_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
*a->a_retval = PATH_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
*a->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-06 20:09:14 +00:00
|
|
|
static int
|
|
|
|
udf_print(struct vop_print_args *ap)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct udf_node *node = VTON(vp);
|
|
|
|
|
|
|
|
printf(" ino %lu, on dev %s", (u_long)node->hash_id,
|
|
|
|
devtoname(node->udfmp->im_dev));
|
|
|
|
if (vp->v_type == VFIFO)
|
|
|
|
fifo_printinfo(vp);
|
|
|
|
printf("\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-01-15 18:45:36 +00:00
|
|
|
#define lblkno(udfmp, loc) ((loc) >> (udfmp)->bshift)
|
|
|
|
#define blkoff(udfmp, loc) ((loc) & (udfmp)->bmask)
|
2009-02-26 12:33:02 +00:00
|
|
|
#define lblktosize(udfmp, blk) ((blk) << (udfmp)->bshift)
|
2007-01-15 18:45:36 +00:00
|
|
|
|
2009-02-26 12:33:12 +00:00
|
|
|
static inline int
|
|
|
|
is_data_in_fentry(const struct udf_node *node)
|
|
|
|
{
|
|
|
|
const struct file_entry *fentry = node->fentry;
|
|
|
|
|
|
|
|
return ((le16toh(fentry->icbtag.flags) & 0x7) == 3);
|
|
|
|
}
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
static int
|
2007-01-15 18:45:36 +00:00
|
|
|
udf_read(struct vop_read_args *ap)
|
2002-04-14 16:52:14 +00:00
|
|
|
{
|
2007-01-15 18:45:36 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
2002-04-14 16:52:14 +00:00
|
|
|
struct udf_node *node = VTON(vp);
|
2007-01-15 18:45:36 +00:00
|
|
|
struct udf_mnt *udfmp;
|
2009-02-26 12:33:12 +00:00
|
|
|
struct file_entry *fentry;
|
2002-04-14 16:52:14 +00:00
|
|
|
struct buf *bp;
|
2009-02-26 12:33:12 +00:00
|
|
|
uint8_t *data;
|
2007-01-15 18:45:36 +00:00
|
|
|
daddr_t lbn, rablock;
|
|
|
|
off_t diff, fsize;
|
2012-02-21 01:05:12 +00:00
|
|
|
ssize_t n;
|
2002-04-14 16:52:14 +00:00
|
|
|
int error = 0;
|
2012-02-21 01:05:12 +00:00
|
|
|
long size, on;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2007-01-15 18:45:36 +00:00
|
|
|
if (uio->uio_resid == 0)
|
|
|
|
return (0);
|
2002-04-14 16:52:14 +00:00
|
|
|
if (uio->uio_offset < 0)
|
|
|
|
return (EINVAL);
|
2009-02-26 12:33:12 +00:00
|
|
|
|
|
|
|
if (is_data_in_fentry(node)) {
|
|
|
|
fentry = node->fentry;
|
|
|
|
data = &fentry->data[le32toh(fentry->l_ea)];
|
|
|
|
fsize = le32toh(fentry->l_ad);
|
|
|
|
|
|
|
|
n = uio->uio_resid;
|
|
|
|
diff = fsize - uio->uio_offset;
|
|
|
|
if (diff <= 0)
|
|
|
|
return (0);
|
|
|
|
if (diff < n)
|
|
|
|
n = diff;
|
|
|
|
error = uiomove(data + uio->uio_offset, (int)n, uio);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-06-23 21:49:03 +00:00
|
|
|
fsize = le64toh(node->fentry->inf_len);
|
2007-01-15 18:45:36 +00:00
|
|
|
udfmp = node->udfmp;
|
|
|
|
do {
|
|
|
|
lbn = lblkno(udfmp, uio->uio_offset);
|
|
|
|
on = blkoff(udfmp, uio->uio_offset);
|
|
|
|
n = min((u_int)(udfmp->bsize - on),
|
|
|
|
uio->uio_resid);
|
|
|
|
diff = fsize - uio->uio_offset;
|
|
|
|
if (diff <= 0)
|
|
|
|
return (0);
|
|
|
|
if (diff < n)
|
|
|
|
n = diff;
|
|
|
|
size = udfmp->bsize;
|
|
|
|
rablock = lbn + 1;
|
|
|
|
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
|
|
|
|
if (lblktosize(udfmp, rablock) < fsize) {
|
2013-03-14 20:28:26 +00:00
|
|
|
error = cluster_read(vp, fsize, lbn, size,
|
|
|
|
NOCRED, uio->uio_resid,
|
|
|
|
(ap->a_ioflag >> 16), 0, &bp);
|
2007-01-15 18:45:36 +00:00
|
|
|
} else {
|
|
|
|
error = bread(vp, lbn, size, NOCRED, &bp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = bread(vp, lbn, size, NOCRED, &bp);
|
|
|
|
}
|
2016-11-22 13:24:57 +00:00
|
|
|
if (error != 0) {
|
2002-04-14 16:52:14 +00:00
|
|
|
brelse(bp);
|
2007-01-15 18:45:36 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2016-11-22 13:24:57 +00:00
|
|
|
n = min(n, size - bp->b_resid);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2007-01-15 18:45:36 +00:00
|
|
|
error = uiomove(bp->b_data + on, (int)n, uio);
|
|
|
|
brelse(bp);
|
|
|
|
} while (error == 0 && uio->uio_resid > 0 && n != 0);
|
2002-04-14 16:52:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the OSTA routines to translate the name from a CS0 dstring to a
|
|
|
|
* 16-bit Unicode String. Hooks need to be placed in here to translate from
|
2003-11-05 06:56:08 +00:00
|
|
|
* Unicode to the encoding that the kernel/user expects. Return the length
|
|
|
|
* of the translated string.
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
|
|
|
static int
|
2003-11-05 06:56:08 +00:00
|
|
|
udf_transname(char *cs0string, char *destname, int len, struct udf_mnt *udfmp)
|
2002-04-14 16:52:14 +00:00
|
|
|
{
|
|
|
|
unicode_t *transname;
|
2003-11-05 06:56:08 +00:00
|
|
|
char *unibuf, *unip;
|
2005-06-05 02:09:48 +00:00
|
|
|
int i, destlen;
|
|
|
|
ssize_t unilen = 0;
|
2003-11-05 06:56:08 +00:00
|
|
|
size_t destleft = MAXNAMLEN;
|
|
|
|
|
|
|
|
/* Convert 16-bit Unicode to destname */
|
|
|
|
if (udfmp->im_flags & UDFMNT_KICONV && udf_iconv) {
|
|
|
|
/* allocate a buffer big enough to hold an 8->16 bit expansion */
|
|
|
|
unibuf = uma_zalloc(udf_zone_trans, M_WAITOK);
|
|
|
|
unip = unibuf;
|
2005-06-05 02:09:48 +00:00
|
|
|
if ((unilen = (ssize_t)udf_UncompressUnicodeByte(len, cs0string, unibuf)) == -1) {
|
2003-11-05 06:56:08 +00:00
|
|
|
printf("udf: Unicode translation failed\n");
|
|
|
|
uma_zfree(udf_zone_trans, unibuf);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2003-11-05 06:56:08 +00:00
|
|
|
while (unilen > 0 && destleft > 0) {
|
2015-01-30 22:01:45 +00:00
|
|
|
udf_iconv->conv(udfmp->im_d2l, __DECONST(const char **,
|
|
|
|
&unibuf), (size_t *)&unilen, (char **)&destname,
|
|
|
|
&destleft);
|
2003-11-05 06:56:08 +00:00
|
|
|
/* Unconverted character found */
|
|
|
|
if (unilen > 0 && destleft > 0) {
|
|
|
|
*destname++ = '?';
|
|
|
|
destleft--;
|
|
|
|
unibuf += 2;
|
|
|
|
unilen -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uma_zfree(udf_zone_trans, unip);
|
|
|
|
*destname = '\0';
|
|
|
|
destlen = MAXNAMLEN - (int)destleft;
|
|
|
|
} else {
|
|
|
|
/* allocate a buffer big enough to hold an 8->16 bit expansion */
|
|
|
|
transname = uma_zalloc(udf_zone_trans, M_WAITOK);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2005-06-05 02:09:48 +00:00
|
|
|
if ((unilen = (ssize_t)udf_UncompressUnicode(len, cs0string, transname)) == -1) {
|
2003-11-05 06:56:08 +00:00
|
|
|
printf("udf: Unicode translation failed\n");
|
|
|
|
uma_zfree(udf_zone_trans, transname);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2003-11-05 06:56:08 +00:00
|
|
|
for (i = 0; i < unilen ; i++) {
|
|
|
|
if (transname[i] & 0xff00) {
|
|
|
|
destname[i] = '.'; /* Fudge the 16bit chars */
|
|
|
|
} else {
|
|
|
|
destname[i] = transname[i] & 0xff;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
2003-11-05 06:56:08 +00:00
|
|
|
uma_zfree(udf_zone_trans, transname);
|
|
|
|
destname[unilen] = 0;
|
2005-06-05 02:09:48 +00:00
|
|
|
destlen = (int)unilen;
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 06:56:08 +00:00
|
|
|
return (destlen);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare a CS0 dstring with a name passed in from the VFS layer. Return
|
2005-05-11 21:10:35 +00:00
|
|
|
* 0 on a successful match, nonzero otherwise. Unicode work may need to be done
|
2002-04-14 16:52:14 +00:00
|
|
|
* here also.
|
|
|
|
*/
|
|
|
|
static int
|
2003-11-05 06:56:08 +00:00
|
|
|
udf_cmpname(char *cs0string, char *cmpname, int cs0len, int cmplen, struct udf_mnt *udfmp)
|
2002-04-14 16:52:14 +00:00
|
|
|
{
|
2002-08-20 04:46:04 +00:00
|
|
|
char *transname;
|
|
|
|
int error = 0;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-20 04:46:04 +00:00
|
|
|
/* This is overkill, but not worth creating a new zone */
|
2003-02-19 05:47:46 +00:00
|
|
|
transname = uma_zalloc(udf_zone_trans, M_WAITOK);
|
2002-08-20 04:46:04 +00:00
|
|
|
|
2003-11-05 06:56:08 +00:00
|
|
|
cs0len = udf_transname(cs0string, transname, cs0len, udfmp);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
/* Easy check. If they aren't the same length, they aren't equal */
|
2002-08-20 04:46:04 +00:00
|
|
|
if ((cs0len == 0) || (cs0len != cmplen))
|
|
|
|
error = -1;
|
|
|
|
else
|
|
|
|
error = bcmp(transname, cmpname, cmplen);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-20 04:46:04 +00:00
|
|
|
uma_zfree(udf_zone_trans, transname);
|
|
|
|
return (error);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct udf_uiodir {
|
|
|
|
struct dirent *dirent;
|
|
|
|
u_long *cookies;
|
|
|
|
int ncookies;
|
|
|
|
int acookies;
|
|
|
|
int eofflag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_uiodir(struct udf_uiodir *uiodir, int de_size, struct uio *uio, long cookie)
|
|
|
|
{
|
|
|
|
if (uiodir->cookies != NULL) {
|
|
|
|
if (++uiodir->acookies > uiodir->ncookies) {
|
|
|
|
uiodir->eofflag = 0;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*uiodir->cookies++ = cookie;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uio->uio_resid < de_size) {
|
|
|
|
uiodir->eofflag = 0;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2003-03-02 15:50:23 +00:00
|
|
|
return (uiomove(uiodir->dirent, de_size, uio));
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
static struct udf_dirstream *
|
|
|
|
udf_opendir(struct udf_node *node, int offset, int fsize, struct udf_mnt *udfmp)
|
|
|
|
{
|
|
|
|
struct udf_dirstream *ds;
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
ds = uma_zalloc(udf_zone_ds, M_WAITOK | M_ZERO);
|
2002-08-15 00:43:43 +00:00
|
|
|
|
|
|
|
ds->node = node;
|
|
|
|
ds->offset = offset;
|
|
|
|
ds->udfmp = udfmp;
|
|
|
|
ds->fsize = fsize;
|
|
|
|
|
|
|
|
return (ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fileid_desc *
|
|
|
|
udf_getfid(struct udf_dirstream *ds)
|
|
|
|
{
|
|
|
|
struct fileid_desc *fid;
|
|
|
|
int error, frag_size = 0, total_fid_size;
|
|
|
|
|
|
|
|
/* End of directory? */
|
|
|
|
if (ds->offset + ds->off >= ds->fsize) {
|
|
|
|
ds->error = 0;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab the first extent of the directory */
|
|
|
|
if (ds->off == 0) {
|
|
|
|
ds->size = 0;
|
|
|
|
error = udf_readatoffset(ds->node, &ds->size, ds->offset,
|
|
|
|
&ds->bp, &ds->data);
|
|
|
|
if (error) {
|
|
|
|
ds->error = error;
|
2004-03-30 05:01:48 +00:00
|
|
|
if (ds->bp != NULL)
|
|
|
|
brelse(ds->bp);
|
2002-08-15 00:43:43 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-15 03:50:06 +00:00
|
|
|
/*
|
|
|
|
* Clean up from a previous fragmented FID.
|
|
|
|
* XXX Is this the right place for this?
|
|
|
|
*/
|
2002-08-15 00:43:43 +00:00
|
|
|
if (ds->fid_fragment && ds->buf != NULL) {
|
|
|
|
ds->fid_fragment = 0;
|
2008-10-23 15:53:51 +00:00
|
|
|
free(ds->buf, M_UDFFID);
|
2002-08-15 00:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fid = (struct fileid_desc*)&ds->data[ds->off];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if the fid is fragmented. The first test
|
|
|
|
* ensures that we don't wander off the end of the buffer
|
|
|
|
* looking for the l_iu and l_fi fields.
|
|
|
|
*/
|
|
|
|
if (ds->off + UDF_FID_SIZE > ds->size ||
|
2004-06-23 21:49:03 +00:00
|
|
|
ds->off + le16toh(fid->l_iu) + fid->l_fi + UDF_FID_SIZE > ds->size){
|
2002-08-15 00:43:43 +00:00
|
|
|
|
|
|
|
/* Copy what we have of the fid into a buffer */
|
|
|
|
frag_size = ds->size - ds->off;
|
|
|
|
if (frag_size >= ds->udfmp->bsize) {
|
|
|
|
printf("udf: invalid FID fragment\n");
|
|
|
|
ds->error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File ID descriptors can only be at most one
|
|
|
|
* logical sector in size.
|
|
|
|
*/
|
2008-10-23 15:53:51 +00:00
|
|
|
ds->buf = malloc(ds->udfmp->bsize, M_UDFFID,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
2002-08-15 00:43:43 +00:00
|
|
|
bcopy(fid, ds->buf, frag_size);
|
|
|
|
|
|
|
|
/* Reduce all of the casting magic */
|
|
|
|
fid = (struct fileid_desc*)ds->buf;
|
|
|
|
|
|
|
|
if (ds->bp != NULL)
|
|
|
|
brelse(ds->bp);
|
|
|
|
|
|
|
|
/* Fetch the next allocation */
|
|
|
|
ds->offset += ds->size;
|
|
|
|
ds->size = 0;
|
|
|
|
error = udf_readatoffset(ds->node, &ds->size, ds->offset,
|
|
|
|
&ds->bp, &ds->data);
|
|
|
|
if (error) {
|
|
|
|
ds->error = error;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the fragment was so small that we didn't get
|
|
|
|
* the l_iu and l_fi fields, copy those in.
|
|
|
|
*/
|
|
|
|
if (frag_size < UDF_FID_SIZE)
|
|
|
|
bcopy(ds->data, &ds->buf[frag_size],
|
|
|
|
UDF_FID_SIZE - frag_size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we have enough of the fid to work with,
|
|
|
|
* copy in the rest of the fid from the new
|
|
|
|
* allocation.
|
|
|
|
*/
|
2004-06-23 21:49:03 +00:00
|
|
|
total_fid_size = UDF_FID_SIZE + le16toh(fid->l_iu) + fid->l_fi;
|
2002-08-15 00:43:43 +00:00
|
|
|
if (total_fid_size > ds->udfmp->bsize) {
|
|
|
|
printf("udf: invalid FID\n");
|
|
|
|
ds->error = EIO;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
bcopy(ds->data, &ds->buf[frag_size],
|
|
|
|
total_fid_size - frag_size);
|
|
|
|
|
|
|
|
ds->fid_fragment = 1;
|
|
|
|
} else {
|
2004-06-23 21:49:03 +00:00
|
|
|
total_fid_size = le16toh(fid->l_iu) + fid->l_fi + UDF_FID_SIZE;
|
2002-08-15 00:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the offset. Align on a 4 byte boundary because the
|
2002-08-15 03:50:06 +00:00
|
|
|
* UDF spec says so.
|
2002-08-15 00:43:43 +00:00
|
|
|
*/
|
2009-03-04 13:54:10 +00:00
|
|
|
ds->this_off = ds->offset + ds->off;
|
2002-08-15 00:43:43 +00:00
|
|
|
if (!ds->fid_fragment) {
|
|
|
|
ds->off += (total_fid_size + 3) & ~0x03;
|
|
|
|
} else {
|
|
|
|
ds->off = (total_fid_size - frag_size + 3) & ~0x03;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (fid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
udf_closedir(struct udf_dirstream *ds)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ds->bp != NULL)
|
|
|
|
brelse(ds->bp);
|
|
|
|
|
|
|
|
if (ds->fid_fragment && ds->buf != NULL)
|
2008-10-23 15:53:51 +00:00
|
|
|
free(ds->buf, M_UDFFID);
|
2002-08-15 00:43:43 +00:00
|
|
|
|
|
|
|
uma_zfree(udf_zone_ds, ds);
|
|
|
|
}
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
static int
|
|
|
|
udf_readdir(struct vop_readdir_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct uio *uio;
|
|
|
|
struct dirent dir;
|
|
|
|
struct udf_node *node;
|
2003-11-05 06:56:08 +00:00
|
|
|
struct udf_mnt *udfmp;
|
2002-04-14 16:52:14 +00:00
|
|
|
struct fileid_desc *fid;
|
|
|
|
struct udf_uiodir uiodir;
|
2002-08-15 00:43:43 +00:00
|
|
|
struct udf_dirstream *ds;
|
2002-04-14 16:52:14 +00:00
|
|
|
u_long *cookies = NULL;
|
|
|
|
int ncookies;
|
2002-08-20 04:46:59 +00:00
|
|
|
int error = 0;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
vp = a->a_vp;
|
|
|
|
uio = a->a_uio;
|
|
|
|
node = VTON(vp);
|
2003-11-05 06:56:08 +00:00
|
|
|
udfmp = node->udfmp;
|
2002-04-14 16:52:14 +00:00
|
|
|
uiodir.eofflag = 1;
|
|
|
|
|
|
|
|
if (a->a_ncookies != NULL) {
|
|
|
|
/*
|
|
|
|
* Guess how many entries are needed. If we run out, this
|
|
|
|
* function will be called again and thing will pick up were
|
|
|
|
* it left off.
|
|
|
|
*/
|
|
|
|
ncookies = uio->uio_resid / 8;
|
2008-10-23 15:53:51 +00:00
|
|
|
cookies = malloc(sizeof(u_long) * ncookies,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_TEMP, M_WAITOK);
|
2002-04-14 16:52:14 +00:00
|
|
|
if (cookies == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
uiodir.ncookies = ncookies;
|
|
|
|
uiodir.cookies = cookies;
|
|
|
|
uiodir.acookies = 0;
|
|
|
|
} else {
|
|
|
|
uiodir.cookies = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate through the file id descriptors. Give the parent dir
|
2002-08-15 03:50:06 +00:00
|
|
|
* entry special attention.
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
2004-06-23 21:49:03 +00:00
|
|
|
ds = udf_opendir(node, uio->uio_offset, le64toh(node->fentry->inf_len),
|
2002-08-15 00:43:43 +00:00
|
|
|
node->udfmp);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
while ((fid = udf_getfid(ds)) != NULL) {
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
/* XXX Should we return an error on a bad fid? */
|
|
|
|
if (udf_checktag(&fid->tag, TAGID_FID)) {
|
|
|
|
printf("Invalid FID tag\n");
|
2003-12-07 05:04:49 +00:00
|
|
|
hexdump(fid, UDF_FID_SIZE, NULL, 0);
|
2002-08-15 00:43:43 +00:00
|
|
|
error = EIO;
|
2002-04-14 16:52:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this a deleted file? */
|
2002-08-04 16:42:20 +00:00
|
|
|
if (fid->file_char & UDF_FILE_CHAR_DEL)
|
2002-08-15 00:43:43 +00:00
|
|
|
continue;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-04 16:42:20 +00:00
|
|
|
if ((fid->l_fi == 0) && (fid->file_char & UDF_FILE_CHAR_PAR)) {
|
2002-04-14 16:52:14 +00:00
|
|
|
/* Do up the '.' and '..' entries. Dummy values are
|
|
|
|
* used for the cookies since the offset here is
|
|
|
|
* usually zero, and NFS doesn't like that value
|
|
|
|
*/
|
2002-08-20 04:46:59 +00:00
|
|
|
dir.d_fileno = node->hash_id;
|
|
|
|
dir.d_type = DT_DIR;
|
|
|
|
dir.d_name[0] = '.';
|
2005-01-14 16:35:34 +00:00
|
|
|
dir.d_name[1] = '\0';
|
2002-08-20 04:46:59 +00:00
|
|
|
dir.d_namlen = 1;
|
|
|
|
dir.d_reclen = GENERIC_DIRSIZ(&dir);
|
|
|
|
uiodir.dirent = &dir;
|
2003-03-02 15:56:49 +00:00
|
|
|
error = udf_uiodir(&uiodir, dir.d_reclen, uio, 1);
|
2002-04-14 16:52:14 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
|
2002-08-20 04:46:59 +00:00
|
|
|
dir.d_fileno = udf_getid(&fid->icb);
|
|
|
|
dir.d_type = DT_DIR;
|
|
|
|
dir.d_name[0] = '.';
|
|
|
|
dir.d_name[1] = '.';
|
2005-01-14 16:35:34 +00:00
|
|
|
dir.d_name[2] = '\0';
|
2002-08-20 04:46:59 +00:00
|
|
|
dir.d_namlen = 2;
|
|
|
|
dir.d_reclen = GENERIC_DIRSIZ(&dir);
|
|
|
|
uiodir.dirent = &dir;
|
|
|
|
error = udf_uiodir(&uiodir, dir.d_reclen, uio, 2);
|
2002-04-14 16:52:14 +00:00
|
|
|
} else {
|
|
|
|
dir.d_namlen = udf_transname(&fid->data[fid->l_iu],
|
2003-11-05 06:56:08 +00:00
|
|
|
&dir.d_name[0], fid->l_fi, udfmp);
|
2002-04-14 16:52:14 +00:00
|
|
|
dir.d_fileno = udf_getid(&fid->icb);
|
2002-08-04 16:42:20 +00:00
|
|
|
dir.d_type = (fid->file_char & UDF_FILE_CHAR_DIR) ?
|
|
|
|
DT_DIR : DT_UNKNOWN;
|
2002-04-14 16:52:14 +00:00
|
|
|
dir.d_reclen = GENERIC_DIRSIZ(&dir);
|
|
|
|
uiodir.dirent = &dir;
|
2002-08-15 00:43:43 +00:00
|
|
|
error = udf_uiodir(&uiodir, dir.d_reclen, uio,
|
|
|
|
ds->this_off);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
2009-02-19 15:05:30 +00:00
|
|
|
if (error)
|
2002-04-14 16:52:14 +00:00
|
|
|
break;
|
2009-03-03 13:10:25 +00:00
|
|
|
uio->uio_offset = ds->offset + ds->off;
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tell the calling layer whether we need to be called again */
|
|
|
|
*a->a_eofflag = uiodir.eofflag;
|
2002-08-15 00:43:43 +00:00
|
|
|
|
2009-02-19 15:37:43 +00:00
|
|
|
if (error < 0)
|
2009-02-19 15:05:30 +00:00
|
|
|
error = 0;
|
2002-08-15 00:43:43 +00:00
|
|
|
if (!error)
|
|
|
|
error = ds->error;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
udf_closedir(ds);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
if (a->a_ncookies != NULL) {
|
|
|
|
if (error)
|
2008-10-23 15:53:51 +00:00
|
|
|
free(cookies, M_TEMP);
|
2002-04-14 16:52:14 +00:00
|
|
|
else {
|
|
|
|
*a->a_ncookies = uiodir.acookies;
|
|
|
|
*a->a_cookies = cookies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_readlink(struct vop_readlink_args *ap)
|
|
|
|
{
|
2009-02-06 22:24:03 +00:00
|
|
|
struct path_component *pc, *end;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct uio uio;
|
|
|
|
struct iovec iov[1];
|
|
|
|
struct udf_node *node;
|
|
|
|
void *buf;
|
|
|
|
char *cp;
|
|
|
|
int error, len, root;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A symbolic link in UDF is a list of variable-length path
|
|
|
|
* component structures. We build a pathname in the caller's
|
|
|
|
* uio by traversing this list.
|
|
|
|
*/
|
|
|
|
vp = ap->a_vp;
|
|
|
|
node = VTON(vp);
|
|
|
|
len = le64toh(node->fentry->inf_len);
|
2010-06-22 08:22:25 +00:00
|
|
|
buf = malloc(len, M_DEVBUF, M_WAITOK);
|
2010-05-31 09:08:44 +00:00
|
|
|
iov[0].iov_len = len;
|
2009-02-06 22:24:03 +00:00
|
|
|
iov[0].iov_base = buf;
|
|
|
|
uio.uio_iov = iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_resid = iov[0].iov_len;
|
|
|
|
uio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
uio.uio_rw = UIO_READ;
|
|
|
|
uio.uio_td = curthread;
|
|
|
|
error = VOP_READ(vp, &uio, 0, ap->a_cred);
|
|
|
|
if (error)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
pc = buf;
|
|
|
|
end = (void *)((char *)buf + len);
|
|
|
|
root = 0;
|
|
|
|
while (pc < end) {
|
|
|
|
switch (pc->type) {
|
|
|
|
case UDF_PATH_ROOT:
|
|
|
|
/* Only allow this at the beginning of a path. */
|
|
|
|
if ((void *)pc != buf) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
cp = "/";
|
|
|
|
len = 1;
|
|
|
|
root = 1;
|
|
|
|
break;
|
|
|
|
case UDF_PATH_DOT:
|
|
|
|
cp = ".";
|
|
|
|
len = 1;
|
|
|
|
break;
|
|
|
|
case UDF_PATH_DOTDOT:
|
|
|
|
cp = "..";
|
|
|
|
len = 2;
|
|
|
|
break;
|
|
|
|
case UDF_PATH_PATH:
|
|
|
|
if (pc->length == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX: We only support CS8 which appears to map
|
|
|
|
* to ASCII directly.
|
|
|
|
*/
|
|
|
|
switch (pc->identifier[0]) {
|
|
|
|
case 8:
|
|
|
|
cp = pc->identifier + 1;
|
|
|
|
len = pc->length - 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is not the first component, insert a path
|
|
|
|
* separator.
|
|
|
|
*/
|
|
|
|
if (pc != buf) {
|
|
|
|
/* If we started with root we already have a "/". */
|
|
|
|
if (root)
|
|
|
|
goto skipslash;
|
|
|
|
root = 0;
|
|
|
|
if (ap->a_uio->uio_resid < 1) {
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
error = uiomove("/", 1, ap->a_uio);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
skipslash:
|
|
|
|
|
|
|
|
/* Append string at 'cp' of length 'len' to our path. */
|
|
|
|
if (len > ap->a_uio->uio_resid) {
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
error = uiomove(cp, len, ap->a_uio);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Advance to next component. */
|
|
|
|
pc = (void *)((char *)pc + 4 + pc->length);
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
return (error);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_strategy(struct vop_strategy_args *a)
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct udf_node *node;
|
2004-10-29 10:40:58 +00:00
|
|
|
struct bufobj *bo;
|
2009-02-26 12:33:02 +00:00
|
|
|
off_t offset;
|
|
|
|
uint32_t maxsize;
|
|
|
|
daddr_t sector;
|
|
|
|
int error;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
bp = a->a_bp;
|
2004-10-27 06:48:21 +00:00
|
|
|
vp = a->a_vp;
|
2002-04-14 16:52:14 +00:00
|
|
|
node = VTON(vp);
|
|
|
|
|
2007-01-15 18:45:36 +00:00
|
|
|
if (bp->b_blkno == bp->b_lblkno) {
|
2009-02-26 12:33:02 +00:00
|
|
|
offset = lblktosize(node->udfmp, bp->b_lblkno);
|
|
|
|
error = udf_bmap_internal(node, offset, §or, &maxsize);
|
|
|
|
if (error) {
|
2002-04-14 16:52:14 +00:00
|
|
|
clrbuf(bp);
|
|
|
|
bp->b_blkno = -1;
|
2009-02-26 12:33:02 +00:00
|
|
|
bufdone(bp);
|
|
|
|
return (0);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
2007-01-15 18:45:36 +00:00
|
|
|
/* bmap gives sector numbers, bio works with device blocks */
|
2009-02-26 12:33:02 +00:00
|
|
|
bp->b_blkno = sector << (node->udfmp->bshift - DEV_BSHIFT);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
2004-10-29 10:40:58 +00:00
|
|
|
bo = node->udfmp->im_bo;
|
2003-10-18 14:10:28 +00:00
|
|
|
bp->b_iooffset = dbtob(bp->b_blkno);
|
2005-01-11 09:10:46 +00:00
|
|
|
BO_STRATEGY(bo, bp);
|
2002-04-14 16:52:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_bmap(struct vop_bmap_args *a)
|
|
|
|
{
|
|
|
|
struct udf_node *node;
|
2002-04-15 19:49:15 +00:00
|
|
|
uint32_t max_size;
|
2002-05-14 11:09:43 +00:00
|
|
|
daddr_t lsector;
|
2009-02-26 12:33:22 +00:00
|
|
|
int nblk;
|
2002-04-14 16:52:14 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
node = VTON(a->a_vp);
|
|
|
|
|
2004-11-15 09:18:27 +00:00
|
|
|
if (a->a_bop != NULL)
|
2005-03-15 21:09:52 +00:00
|
|
|
*a->a_bop = &node->udfmp->im_devvp->v_bufobj;
|
2002-04-14 16:52:14 +00:00
|
|
|
if (a->a_bnp == NULL)
|
|
|
|
return (0);
|
|
|
|
if (a->a_runb)
|
|
|
|
*a->a_runb = 0;
|
|
|
|
|
2009-02-26 12:33:17 +00:00
|
|
|
/*
|
|
|
|
* UDF_INVALID_BMAP means data embedded into fentry, this is an internal
|
|
|
|
* error that should not be propagated to calling code.
|
|
|
|
* Most obvious mapping for this error is EOPNOTSUPP as we can not truly
|
|
|
|
* translate block numbers in this case.
|
|
|
|
* Incidentally, this return code will make vnode pager to use VOP_READ
|
|
|
|
* to get data for mmap-ed pages and udf_read knows how to do the right
|
|
|
|
* thing for this kind of files.
|
|
|
|
*/
|
|
|
|
error = udf_bmap_internal(node, a->a_bn << node->udfmp->bshift,
|
|
|
|
&lsector, &max_size);
|
|
|
|
if (error == UDF_INVALID_BMAP)
|
|
|
|
return (EOPNOTSUPP);
|
2002-08-02 06:22:20 +00:00
|
|
|
if (error)
|
2002-04-14 16:52:14 +00:00
|
|
|
return (error);
|
|
|
|
|
2002-05-02 05:01:14 +00:00
|
|
|
/* Translate logical to physical sector number */
|
|
|
|
*a->a_bnp = lsector << (node->udfmp->bshift - DEV_BSHIFT);
|
|
|
|
|
2009-02-26 12:33:22 +00:00
|
|
|
/*
|
|
|
|
* Determine maximum number of readahead blocks following the
|
|
|
|
* requested block.
|
|
|
|
*/
|
|
|
|
if (a->a_runp) {
|
|
|
|
nblk = (max_size >> node->udfmp->bshift) - 1;
|
|
|
|
if (nblk <= 0)
|
|
|
|
*a->a_runp = 0;
|
|
|
|
else if (nblk >= (MAXBSIZE >> node->udfmp->bshift))
|
|
|
|
*a->a_runp = (MAXBSIZE >> node->udfmp->bshift) - 1;
|
|
|
|
else
|
|
|
|
*a->a_runp = nblk;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->a_runb) {
|
|
|
|
*a->a_runb = 0;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The all powerful VOP_LOOKUP().
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
udf_lookup(struct vop_cachedlookup_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *dvp;
|
|
|
|
struct vnode *tdp = NULL;
|
|
|
|
struct vnode **vpp = a->a_vpp;
|
|
|
|
struct udf_node *node;
|
|
|
|
struct udf_mnt *udfmp;
|
|
|
|
struct fileid_desc *fid = NULL;
|
2002-08-15 00:43:43 +00:00
|
|
|
struct udf_dirstream *ds;
|
2002-04-14 16:52:14 +00:00
|
|
|
u_long nameiop;
|
|
|
|
u_long flags;
|
|
|
|
char *nameptr;
|
|
|
|
long namelen;
|
|
|
|
ino_t id = 0;
|
2002-08-15 00:43:43 +00:00
|
|
|
int offset, error = 0;
|
2009-02-09 20:50:23 +00:00
|
|
|
int fsize, lkflags, ltype, numdirpasses;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
dvp = a->a_dvp;
|
|
|
|
node = VTON(dvp);
|
|
|
|
udfmp = node->udfmp;
|
|
|
|
nameiop = a->a_cnp->cn_nameiop;
|
|
|
|
flags = a->a_cnp->cn_flags;
|
2009-02-09 20:50:23 +00:00
|
|
|
lkflags = a->a_cnp->cn_lkflags;
|
2002-04-14 16:52:14 +00:00
|
|
|
nameptr = a->a_cnp->cn_nameptr;
|
|
|
|
namelen = a->a_cnp->cn_namelen;
|
2004-06-23 21:49:03 +00:00
|
|
|
fsize = le64toh(node->fentry->inf_len);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a LOOKUP and we've already partially searched through
|
|
|
|
* the directory, pick up where we left off and flag that the
|
|
|
|
* directory may need to be searched twice. For a full description,
|
2007-03-24 22:40:16 +00:00
|
|
|
* see /sys/fs/cd9660/cd9660_lookup.c:cd9660_lookup()
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
2002-08-15 00:43:43 +00:00
|
|
|
if (nameiop != LOOKUP || node->diroff == 0 || node->diroff > fsize) {
|
2002-04-14 16:52:14 +00:00
|
|
|
offset = 0;
|
|
|
|
numdirpasses = 1;
|
|
|
|
} else {
|
|
|
|
offset = node->diroff;
|
|
|
|
numdirpasses = 2;
|
|
|
|
nchstats.ncs_2passes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
lookloop:
|
2002-08-15 00:43:43 +00:00
|
|
|
ds = udf_opendir(node, offset, fsize, udfmp);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
while ((fid = udf_getfid(ds)) != NULL) {
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
/* XXX Should we return an error on a bad fid? */
|
2002-08-15 00:43:43 +00:00
|
|
|
if (udf_checktag(&fid->tag, TAGID_FID)) {
|
|
|
|
printf("udf_lookup: Invalid tag\n");
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
}
|
2002-08-02 06:19:43 +00:00
|
|
|
|
|
|
|
/* Is this a deleted file? */
|
2002-08-04 16:42:20 +00:00
|
|
|
if (fid->file_char & UDF_FILE_CHAR_DEL)
|
2002-08-15 00:43:43 +00:00
|
|
|
continue;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-04 16:42:20 +00:00
|
|
|
if ((fid->l_fi == 0) && (fid->file_char & UDF_FILE_CHAR_PAR)) {
|
2002-04-14 16:52:14 +00:00
|
|
|
if (flags & ISDOTDOT) {
|
|
|
|
id = udf_getid(&fid->icb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(udf_cmpname(&fid->data[fid->l_iu],
|
2003-11-05 06:56:08 +00:00
|
|
|
nameptr, fid->l_fi, namelen, udfmp))) {
|
2002-04-14 16:52:14 +00:00
|
|
|
id = udf_getid(&fid->icb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-08-15 00:43:43 +00:00
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
if (!error)
|
|
|
|
error = ds->error;
|
|
|
|
|
|
|
|
/* XXX Bail out here? */
|
|
|
|
if (error) {
|
|
|
|
udf_closedir(ds);
|
|
|
|
return (error);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we have a match? */
|
|
|
|
if (id) {
|
2009-02-09 20:50:23 +00:00
|
|
|
/*
|
|
|
|
* Remember where this entry was if it's the final
|
|
|
|
* component.
|
|
|
|
*/
|
|
|
|
if ((flags & ISLASTCN) && nameiop == LOOKUP)
|
|
|
|
node->diroff = ds->offset + ds->off;
|
|
|
|
if (numdirpasses == 2)
|
|
|
|
nchstats.ncs_pass2++;
|
|
|
|
udf_closedir(ds);
|
|
|
|
|
|
|
|
if (flags & ISDOTDOT) {
|
|
|
|
error = vn_vget_ino(dvp, id, lkflags, &tdp);
|
|
|
|
} else if (node->hash_id == id) {
|
|
|
|
VREF(dvp); /* we want ourself, ie "." */
|
2002-08-15 00:43:43 +00:00
|
|
|
/*
|
2009-02-09 20:50:23 +00:00
|
|
|
* When we lookup "." we still can be asked to lock it
|
|
|
|
* differently.
|
2002-08-15 00:43:43 +00:00
|
|
|
*/
|
2009-02-09 20:50:23 +00:00
|
|
|
ltype = lkflags & LK_TYPE_MASK;
|
|
|
|
if (ltype != VOP_ISLOCKED(dvp)) {
|
|
|
|
if (ltype == LK_EXCLUSIVE)
|
|
|
|
vn_lock(dvp, LK_UPGRADE | LK_RETRY);
|
|
|
|
else /* if (ltype == LK_SHARED) */
|
|
|
|
vn_lock(dvp, LK_DOWNGRADE | LK_RETRY);
|
|
|
|
}
|
|
|
|
tdp = dvp;
|
|
|
|
} else
|
|
|
|
error = udf_vget(udfmp->im_mountp, id, lkflags, &tdp);
|
|
|
|
if (!error) {
|
2002-08-15 00:43:43 +00:00
|
|
|
*vpp = tdp;
|
|
|
|
/* Put this entry in the cache */
|
|
|
|
if (flags & MAKEENTRY)
|
|
|
|
cache_enter(dvp, *vpp, a->a_cnp);
|
2005-04-13 10:59:09 +00:00
|
|
|
}
|
2002-08-15 00:43:43 +00:00
|
|
|
} else {
|
|
|
|
/* Name wasn't found on this pass. Do another pass? */
|
|
|
|
if (numdirpasses == 2) {
|
|
|
|
numdirpasses--;
|
|
|
|
offset = 0;
|
|
|
|
udf_closedir(ds);
|
|
|
|
goto lookloop;
|
|
|
|
}
|
2009-02-09 20:50:23 +00:00
|
|
|
udf_closedir(ds);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
/* Enter name into cache as non-existant */
|
2002-04-14 16:52:14 +00:00
|
|
|
if (flags & MAKEENTRY)
|
|
|
|
cache_enter(dvp, *vpp, a->a_cnp);
|
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
if ((flags & ISLASTCN) &&
|
|
|
|
(nameiop == CREATE || nameiop == RENAME)) {
|
|
|
|
error = EROFS;
|
|
|
|
} else {
|
|
|
|
error = ENOENT;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2002-08-15 00:43:43 +00:00
|
|
|
return (error);
|
2002-04-14 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_reclaim(struct vop_reclaim_args *a)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct udf_node *unode;
|
|
|
|
|
|
|
|
vp = a->a_vp;
|
|
|
|
unode = VTON(vp);
|
|
|
|
|
2006-01-17 17:29:03 +00:00
|
|
|
/*
|
|
|
|
* Destroy the vm object and flush associated pages.
|
|
|
|
*/
|
|
|
|
vnode_destroy_vobject(vp);
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
if (unode != NULL) {
|
2005-03-14 12:29:39 +00:00
|
|
|
vfs_hash_remove(vp);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
if (unode->fentry != NULL)
|
2008-10-23 15:53:51 +00:00
|
|
|
free(unode->fentry, M_UDFFENTRY);
|
2002-04-14 16:52:14 +00:00
|
|
|
uma_zfree(udf_zone_node, unode);
|
|
|
|
vp->v_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-02-15 22:08:35 +00:00
|
|
|
static int
|
|
|
|
udf_vptofh(struct vop_vptofh_args *a)
|
|
|
|
{
|
|
|
|
struct udf_node *node;
|
|
|
|
struct ifid *ifhp;
|
|
|
|
|
|
|
|
node = VTON(a->a_vp);
|
|
|
|
ifhp = (struct ifid *)a->a_fhp;
|
|
|
|
ifhp->ifid_len = sizeof(struct ifid);
|
|
|
|
ifhp->ifid_ino = node->hash_id;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-04-14 16:52:14 +00:00
|
|
|
/*
|
2003-03-02 15:56:49 +00:00
|
|
|
* Read the block and then set the data pointer to correspond with the
|
2002-04-14 16:52:14 +00:00
|
|
|
* offset passed in. Only read in at most 'size' bytes, and then set 'size'
|
|
|
|
* to the number of bytes pointed to. If 'size' is zero, try to read in a
|
|
|
|
* whole extent.
|
2004-03-30 05:01:48 +00:00
|
|
|
*
|
|
|
|
* Note that *bp may be assigned error or not.
|
|
|
|
*
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
|
|
|
static int
|
2005-01-12 06:42:13 +00:00
|
|
|
udf_readatoffset(struct udf_node *node, int *size, off_t offset,
|
|
|
|
struct buf **bp, uint8_t **data)
|
2002-04-14 16:52:14 +00:00
|
|
|
{
|
2009-02-26 18:58:41 +00:00
|
|
|
struct udf_mnt *udfmp = node->udfmp;
|
|
|
|
struct vnode *vp = node->i_vnode;
|
|
|
|
struct file_entry *fentry;
|
2002-04-14 16:52:14 +00:00
|
|
|
struct buf *bp1;
|
2002-04-15 19:49:15 +00:00
|
|
|
uint32_t max_size;
|
2002-05-14 11:09:43 +00:00
|
|
|
daddr_t sector;
|
2009-02-26 18:58:41 +00:00
|
|
|
off_t off;
|
|
|
|
int adj_size;
|
2002-04-14 16:52:14 +00:00
|
|
|
int error;
|
|
|
|
|
2009-02-26 18:58:41 +00:00
|
|
|
/*
|
|
|
|
* This call is made *not* only to detect UDF_INVALID_BMAP case,
|
|
|
|
* max_size is used as an ad-hoc read-ahead hint for "normal" case.
|
|
|
|
*/
|
2002-04-14 16:52:14 +00:00
|
|
|
error = udf_bmap_internal(node, offset, §or, &max_size);
|
2002-08-15 03:50:06 +00:00
|
|
|
if (error == UDF_INVALID_BMAP) {
|
2002-04-14 16:52:14 +00:00
|
|
|
/*
|
|
|
|
* This error means that the file *data* is stored in the
|
|
|
|
* allocation descriptor field of the file entry.
|
|
|
|
*/
|
|
|
|
fentry = node->fentry;
|
2004-06-23 21:49:03 +00:00
|
|
|
*data = &fentry->data[le32toh(fentry->l_ea)];
|
|
|
|
*size = le32toh(fentry->l_ad);
|
2009-02-27 17:29:31 +00:00
|
|
|
if (offset >= *size)
|
|
|
|
*size = 0;
|
|
|
|
else {
|
|
|
|
*data += offset;
|
|
|
|
*size -= offset;
|
|
|
|
}
|
2002-04-14 16:52:14 +00:00
|
|
|
return (0);
|
|
|
|
} else if (error != 0) {
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-04-30 05:05:05 +00:00
|
|
|
/* Adjust the size so that it is within range */
|
2002-04-14 16:52:14 +00:00
|
|
|
if (*size == 0 || *size > max_size)
|
|
|
|
*size = max_size;
|
|
|
|
|
2009-02-26 18:58:41 +00:00
|
|
|
/*
|
|
|
|
* Because we will read starting at block boundary, we need to adjust
|
|
|
|
* how much we need to read so that all promised data is in.
|
|
|
|
* Also, we can't promise to read more than MAXBSIZE bytes starting
|
|
|
|
* from block boundary, so adjust what we promise too.
|
|
|
|
*/
|
|
|
|
off = blkoff(udfmp, offset);
|
|
|
|
*size = min(*size, MAXBSIZE - off);
|
|
|
|
adj_size = (*size + off + udfmp->bmask) & ~udfmp->bmask;
|
|
|
|
*bp = NULL;
|
|
|
|
if ((error = bread(vp, lblkno(udfmp, offset), adj_size, NOCRED, bp))) {
|
2003-05-04 07:39:11 +00:00
|
|
|
printf("warning: udf_readlblks returned error %d\n", error);
|
2004-03-30 05:01:48 +00:00
|
|
|
/* note: *bp may be non-NULL */
|
2002-04-14 16:52:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
bp1 = *bp;
|
2007-06-11 20:14:44 +00:00
|
|
|
*data = (uint8_t *)&bp1->b_data[offset & udfmp->bmask];
|
2002-04-14 16:52:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a file offset into a logical block and then into a physical
|
|
|
|
* block.
|
2007-06-11 20:14:44 +00:00
|
|
|
* max_size - maximum number of bytes that can be read starting from given
|
|
|
|
* offset, rather than beginning of calculated sector number
|
2002-04-14 16:52:14 +00:00
|
|
|
*/
|
|
|
|
static int
|
2005-01-12 06:42:13 +00:00
|
|
|
udf_bmap_internal(struct udf_node *node, off_t offset, daddr_t *sector,
|
|
|
|
uint32_t *max_size)
|
2002-04-14 16:52:14 +00:00
|
|
|
{
|
|
|
|
struct udf_mnt *udfmp;
|
|
|
|
struct file_entry *fentry;
|
|
|
|
void *icb;
|
|
|
|
struct icb_tag *tag;
|
2002-04-15 19:49:15 +00:00
|
|
|
uint32_t icblen = 0;
|
2002-05-14 11:09:43 +00:00
|
|
|
daddr_t lsector;
|
2002-04-14 16:52:14 +00:00
|
|
|
int ad_offset, ad_num = 0;
|
|
|
|
int i, p_offset;
|
|
|
|
|
|
|
|
udfmp = node->udfmp;
|
|
|
|
fentry = node->fentry;
|
|
|
|
tag = &fentry->icbtag;
|
|
|
|
|
2004-06-23 21:49:03 +00:00
|
|
|
switch (le16toh(tag->strat_type)) {
|
2002-04-14 16:52:14 +00:00
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4096:
|
|
|
|
printf("Cannot deal with strategy4096 yet!\n");
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unknown strategy type %d\n", tag->strat_type);
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
|
|
|
|
2004-06-23 21:49:03 +00:00
|
|
|
switch (le16toh(tag->flags) & 0x7) {
|
2002-04-14 16:52:14 +00:00
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* The allocation descriptor field is filled with short_ad's.
|
|
|
|
* If the offset is beyond the current extent, look for the
|
|
|
|
* next extent.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
offset -= icblen;
|
|
|
|
ad_offset = sizeof(struct short_ad) * ad_num;
|
2004-06-23 21:49:03 +00:00
|
|
|
if (ad_offset > le32toh(fentry->l_ad)) {
|
2002-04-14 16:52:14 +00:00
|
|
|
printf("File offset out of bounds\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2005-01-18 10:15:23 +00:00
|
|
|
icb = GETICB(short_ad, fentry,
|
2004-06-23 21:49:03 +00:00
|
|
|
le32toh(fentry->l_ea) + ad_offset);
|
2002-04-14 16:52:14 +00:00
|
|
|
icblen = GETICBLEN(short_ad, icb);
|
|
|
|
ad_num++;
|
|
|
|
} while(offset >= icblen);
|
|
|
|
|
|
|
|
lsector = (offset >> udfmp->bshift) +
|
2006-02-03 15:25:52 +00:00
|
|
|
le32toh(((struct short_ad *)(icb))->pos);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2007-06-11 20:14:44 +00:00
|
|
|
*max_size = icblen - offset;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/*
|
|
|
|
* The allocation descriptor field is filled with long_ad's
|
|
|
|
* If the offset is beyond the current extent, look for the
|
|
|
|
* next extent.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
offset -= icblen;
|
|
|
|
ad_offset = sizeof(struct long_ad) * ad_num;
|
2004-06-23 21:49:03 +00:00
|
|
|
if (ad_offset > le32toh(fentry->l_ad)) {
|
2002-04-14 16:52:14 +00:00
|
|
|
printf("File offset out of bounds\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2004-06-23 21:49:03 +00:00
|
|
|
icb = GETICB(long_ad, fentry,
|
|
|
|
le32toh(fentry->l_ea) + ad_offset);
|
2002-04-14 16:52:14 +00:00
|
|
|
icblen = GETICBLEN(long_ad, icb);
|
|
|
|
ad_num++;
|
|
|
|
} while(offset >= icblen);
|
|
|
|
|
2003-03-02 15:56:49 +00:00
|
|
|
lsector = (offset >> udfmp->bshift) +
|
2004-06-23 21:49:03 +00:00
|
|
|
le32toh(((struct long_ad *)(icb))->loc.lb_num);
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2007-06-11 20:14:44 +00:00
|
|
|
*max_size = icblen - offset;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/*
|
|
|
|
* This type means that the file *data* is stored in the
|
|
|
|
* allocation descriptor field of the file entry.
|
|
|
|
*/
|
|
|
|
*max_size = 0;
|
2002-08-02 06:22:20 +00:00
|
|
|
*sector = node->hash_id + udfmp->part_start;
|
2002-04-14 16:52:14 +00:00
|
|
|
|
2002-08-15 03:50:06 +00:00
|
|
|
return (UDF_INVALID_BMAP);
|
2002-04-14 16:52:14 +00:00
|
|
|
case 2:
|
|
|
|
/* DirectCD does not use extended_ad's */
|
|
|
|
default:
|
|
|
|
printf("Unsupported allocation descriptor %d\n",
|
|
|
|
tag->flags & 0x7);
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
*sector = lsector + udfmp->part_start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the sparing table. Each entry represents the beginning of
|
|
|
|
* a packet.
|
|
|
|
*/
|
|
|
|
if (udfmp->s_table != NULL) {
|
|
|
|
for (i = 0; i< udfmp->s_table_entries; i++) {
|
2004-06-23 21:49:03 +00:00
|
|
|
p_offset =
|
|
|
|
lsector - le32toh(udfmp->s_table->entries[i].org);
|
2002-04-14 16:52:14 +00:00
|
|
|
if ((p_offset < udfmp->p_sectors) && (p_offset >= 0)) {
|
2004-06-23 21:49:03 +00:00
|
|
|
*sector =
|
|
|
|
le32toh(udfmp->s_table->entries[i].map) +
|
2002-04-14 16:52:14 +00:00
|
|
|
p_offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|