udf_subr.c revision b39a0235a975290e229a1bf1de8031578ab2d98d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <sys/sysmacros.h>
#include <sys/resource.h>
#include <sys/pathname.h>
#include <sys/bootconf.h>
#include <vm/seg_kmem.h>
/*
* HASH chains and mutex
*/
extern kmutex_t ud_icache_lock;
extern kmutex_t ud_sync_busy;
/*
* udf_vfs list manipulation routines
*/
extern kmutex_t udf_vfs_mutex;
extern struct udf_vfs *udf_vfs_instances;
/*
* Used to verify that a given entry on the udf_instances list (see below)
* still refers to a mounted file system.
*
* XXX: This is a crock that substitutes for proper locking to coordinate
* updates to and uses of the entries in udf_instances.
*/
struct check_node {
};
void ud_checkclean(struct vfs *,
/*
* Link udf_vfsp in at the head of the list of udf_vfs_instances.
*/
void
{
}
/*
* Remove udf_vfsp from the list of udf_vfs_instances.
*
* Does no error checking; udf_vfsp is assumed to actually be on the list.
*/
void
{
break;
}
}
}
/*
* Search for the prn in the array
* of partitions and translate
* to the disk block number
*/
{
int32_t i;
ud_printf("ud_xlate_to_daddr\n");
/* Is prn valid */
/*
* Map is Virtual Parition Map
* first check for the appropriate
* table and then return the converted
* block number
*/
*count = 1;
break;
} else {
}
}
struct stbl_entry *te;
/*
* Map type is Sparable Parition Map
* if the block is in the map
* return the translated block
* other wise use the regular
* partition stuff
*/
for (i = 0; i < entry_count; i++, te++) {
/*
* Either unmapped or reserved
* or defective. need not consider
*/
continue;
}
continue;
}
} else {
} else {
}
goto end;
}
}
} else {
/*
* regular partition
*/
}
/*
* Check if the block is inside
* the partition or not
*/
retblkno = 0;
} else {
}
goto end;
}
ud_parts ++;
}
}
end:
return (retblkno);
}
#ifdef UNDEF
{
int32_t i;
ud_printf("ud_xlate_to_addr\n");
if (lad == 0) {
return (blkno);
}
}
}
return (0);
}
#endif
/*
* Directories do not have holes
*/
{
return (0);
}
return (error);
}
for (i = 0; i < ip->i_ext_used; i++) {
break;
}
}
return (0);
}
0x0, 0x28de80, 0x4dc880, 0x76a700, 0x9e3400, 0xc71280,
0xee9f80, 0x1177e00, 0x1405c80, 0x167e980, 0x190c800, 0x1b85500
};
static uint32_t cum_sec_leap[] = {
0x0, 0x28de80, 0x4f1a00, 0x77f880, 0x9f8580, 0xc86400,
0xeff100, 0x118cf80, 0x141ae00, 0x1693b00, 0x1921980, 0x1b9a680
};
#define DAYS_PER_YEAR 365
#define SEC_PER_DAY 0x15180
#define SEC_PER_YEAR 0x1e13380
/* This holds good till yr 2100 */
void
{
ud_printf("ud_dtime2utime\n");
/* Local time */
/*
* Sign extend the tzone
*/
} else {
}
sec *= 60;
}
}
if (year >= 1970) {
} else {
}
}
}
void
{
ud_printf("ud_utime2dtime\n");
if (sec < 0) {
before = 1;
if (usec) {
}
}
usec %= 10000;
if (before == 0) {
} else {
}
nyrs--;
if (before == 0) {
} else {
}
}
if (before == 1) {
if (sec != 0) {
nyrs --;
if ((nyrs % 4) == 0) {
} else {
}
}
} else {
nyrs += 1970;
}
if (dummy > 11) {
dummy = 11;
}
dummy--;
}
/* GMT offset is 0 */
}
{
ud_printf("ud_syncip\n");
return (0);
}
error = 0;
} else {
}
}
return (error);
}
/* ARGSUSED */
{
ud_printf("ud_fbwrite\n");
}
void
{
struct log_vol_int_desc *lvid;
int32_t i, c;
ud_printf("ud_sbwrite\n");
/*
* updatable information in the superblock
* integrity type, udf_maxuniq, udf_nfiles, udf_ndirs
* udp_nfree in lvid
*/
} else {
}
for (i = 0; i < c; i++) {
ud_part++;
}
sizeof (struct log_vol_int_desc) - 8 +
/*
* Don't release the buffer after writing to the disk
*/
}
{
ud_printf("ud_sync_indir\n");
return (0);
} else {
return (EINVAL);
}
return (0);
}
} else {
return (EINVAL);
}
return (0);
}
void
{
ud_printf("ud_update\n");
/*
* Examine all udf_vfs structures and add those that we can lock to the
* update list. This is so that we don't hold the list lock for a
* long time. If vfs_lock fails for a file system instance, then skip
* it because somebody is doing a unmount on it.
*/
for (udfsp = udf_vfs_instances;
continue;
}
update_list = udfsp;
check_cnt++;
}
if (update_list == NULL) {
return;
}
/*
* Write back modified superblocks.
* Consistency check that the superblock of
* each file system is still in the buffer cache.
*
* Note that the update_list traversal is done without the protection
* of an overall list lock, so it's necessary to rely on the fact that
* each entry of the list is vfs_locked when moving from one entry to
* the next. This works because a concurrent attempt to add an entry
* to another thread's update_list won't find it, since it'll already
* be locked.
*/
check_cnt = 0;
/*
* Need to grab the next ptr before we unlock this one so
* another thread doesn't grab it and change it before we move
* on to the next vfs. (Once we unlock it, it's ok if another
* thread finds it to add it to its own update_list; we don't
* attempt to refer to it through our list any more.)
*/
continue;
}
/*
* Build up the STABLE check list, so we can unlock the vfs
* until we do the actual checking.
*/
if (check_list != NULL) {
ptr++;
check_cnt++;
}
}
/*
* superblock is not modified
*/
continue;
}
return;
}
}
/*
* Force stale buffer cache information to be flushed,
* for all devices. This should cause any remaining control
* information (e.g., inode info) to be flushed back.
*/
if (check_list == NULL) {
return;
}
/*
* For each udf filesystem in the STABLE check_list, update
* the clean flag if warranted.
*/
/*
* ud_still_mounted() returns with vfsp and the vfs_reflock
* held if ptr refers to a vfs that is still mounted.
*/
continue;
}
}
}
/*
* Returns vfsp and hold the lock if the vfs is still being mounted.
* Otherwise, returns 0.
*
* For our purposes, "still mounted" means that the file system still appears
* on the list of UFS file system instances.
*/
vfs_t *
{
ud_printf("ud_still_mounted\n");
for (udf_vfsp = udf_vfs_instances;
continue;
}
/*
* Tentative match: verify it and try to lock. (It's not at
* all clear how the verification could fail, given that we've
* gotten this far. We would have had to reallocate the
* ufsvfs struct at hand for a new incarnation; is that really
* possible in the interval from constructing the check_node
* to here?)
*/
continue;
}
continue;
}
continue;
}
return (vfsp);
}
return (NULL);
}
/* ARGSUSED */
void
{
ud_printf("ud_checkclean\n");
/*
* ignore if buffers or inodes are busy
*/
return;
}
}
{
error = 1;
goto end;
}
}
}
end:
return (error);
}
void
{
/*
* Write back each (modified) inode,
* but don't sync back pages if vnode is
* part of the virtual swap device.
*/
/*
* Skip locked & inactive inodes.
* Skip vnodes w/ no cached data and no inode changes.
* Skip read-only vnodes
*/
(!vn_has_cached_data(vp) &&
continue;
}
continue;
}
}
/*
* If this is an inode sync for file system hardening
* or this is a full sync but file is a swap file,
* don't sync pages but make sure the inode is up
* to date. In other cases, push everything out.
*/
} else {
}
}
}
}
}
void
{
ud_printf("ud_update_regid\n");
}
/* ARGSUSED4 */
void
{
int32_t i;
ud_printf("ud_make_tag\n");
for (i = 0; i <= 15; i++) {
}
}
{
ud_printf("ud_make_dev_spec_ear\n");
attr_len = sizeof (struct dev_spec_ear);
return (attr_len);
}
{
ud_printf("ud_get_next_fid\n");
return (error);
}
/* First time read */
return (error);
}
}
(offset == 0)) {
} else {
sz = 0;
}
} else {
copied = 1;
/* Skip to next block */
}
return (error);
}
}
/*
* Check if this a valid file_identifier
*/
/*
* Either end of directory or corrupted
*/
return (EINVAL);
}
/*
* Entries cannot be larger than
* blocksize
*/
return (EINVAL);
}
goto use_id_iu_len;
}
/*
* By now beg points to the start fo the file name
*/
if (copied == 1) {
}
} else {
copied = 1;
/*
* We are releasing the
* old buffer so copy fid to buf
*/
} else {
}
/* Skip to next block */
}
return (error);
}
}
/*
* First we verify that the tag id and the FID_LEN are valid.
* Next we verify the crc of the descriptor.
*/
/* directory is corrupted */
return (EINVAL);
}
/* directory is corrupted */
return (EINVAL);
}
if (copied == 1) {
}
} else {
} else {
}
/* Skip to next block */
}
return (error);
}
}
}
return (0);
}
{
int32_t i;
struct ext_attr_hdr *eah;
return (1);
}
for (i = 0; i < 4; i++) {
}
for (i = 5; i <= 15; i++) {
}
"Checksum Does not Verify TAG %x CALC %x blockno 0x%x\n",
return (1);
}
/*
* Validate the meta data for UD_FILE_ID_DESC.
* The FID_LEN should not exceed the desc_len.
* This validation is done before the entire descriptor is read.
* A call to this routine is made initially with verify_desc set as 0
* but a non zero value in desc_len.
*/
if (id == UD_FILE_ID_DESC) {
"Invalid FID_LEN(0x%x). Greater than expected(0x%x) blockno 0x%x\n",
return (1);
}
}
if (verify_desc == 0)
return (0);
/*
* We are done verifying the tag. We proceed with verifying the
* the descriptor. desc_len indicates the size of the structure
* pointed to by argument tag. It includes the size of struct tag.
* We first check the tag_crc_len since we use this to compute the
* crc of the descriptor.
* Verifying the crc is normally sufficient to ensure the integrity
* of the meta data in the descriptor. However given the paranoia
* about the panic caused by illegal meta data values we do an
* additional check of the meta data for decriptor UD_FILE_ENTRY.
* (The original panic was caused because this routine was not called
* to verify the integrity of the tag and descriptor.)
*/
"tag_crc_len(0x%x) is greater than expected len(0x%x) blockno 0x%x\n",
return (1);
}
if (tag->tag_crc_len) {
" Computed crc 0x%x tag_loc %x blockno 0x%x\n",
return (1);
}
}
switch (id) {
case UD_FILE_ENTRY:
"fe_len_ear(0x%x) fe_len_adesc(0x%x) fields are not OK. blockno 0x%x\n",
blockno);
return (1);
}
break;
case UD_EXT_ATTR_HDR:
"eah_all(0x%x) exceeds desc. len(0x%x) blockno 0x%x\n",
return (1);
}
"ea_off(0x%x) is not less than ea_len(0x%x) blockno 0x%x\n",
return (1);
}
break;
default:
break;
}
"Tag Location mismatch blockno %x tag_blockno %x\n",
return (1);
}
return (0);
}
/* **************** udf specific subroutines *********************** */
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
{
while (len-- > 0) {
}
return (crc);
}
typedef unsigned short unicode_t;
#define POUND 0x0023
#define DOT 0x002E
#define SLASH 0x002F
#define UNDERBAR 0x005F
'4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/*
* An unrecorded block will return all
* 0's on a WORM media. to simulate
* a unrecorded block on a rw media
* we fill it with all zero's
* return 0 : If unrecorded
* return 1 : If recorded.
*/
{
struct term_entry *te;
for (i = 0; i < lbsize; i++) {
if (addr[i] != 0) {
return (1);
}
}
}
return (0);
}
/*
* The algorithms ud_utf82utf16 and ud_utf162utf8
* donot handle surrogates. This is unicode 1.1 as I
* understand. When writing udf2.0 this code has
* to be changed to process surrogates also
* (Dont ask me what is a surrogate character)
*/
/*
* This will take a utf8 string convert the first character
* to utf16 and return the number of bytes consumed in this
* process. A 0 will be returned if the character is invalid
*/
uint8_t bytes_from_utf8[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
};
{
/*
* First convert to a 32-bit
* character
*/
c_32 = 0;
if (extra_bytes > count) {
return (0);
}
/*
* verify if the string is a valid
* utf8 string
*/
if (extra_bytes == 0) {
/*
* Apply one byte rule
*/
if (*s_8 & 0x80) {
return (0);
}
} else if (extra_bytes == 1) {
return (0);
}
} else if (extra_bytes == 2) {
return (0);
}
} else if (extra_bytes == 3) {
return (0);
}
} else if (extra_bytes == 4) {
return (0);
}
} else if (extra_bytes == 5) {
return (0);
}
} else {
return (0);
}
s_8++;
/*
* Convert to 32-bit character
*/
switch (extra_bytes) {
case 5 :
c_32 <<= 6;
/* FALLTHROUGH */
case 4 :
c_32 <<= 6;
/* FALLTHROUGH */
case 3 :
c_32 <<= 6;
/* FALLTHROUGH */
case 2 :
c_32 <<= 6;
/* FALLTHROUGH */
case 1 :
c_32 <<= 6;
/* FALLTHROUGH */
case 0 :
break;
}
/*
* now convert the 32-bit
* character into a 16-bit character
*/
return (extra_bytes + 1);
}
/*
* Convert to a form that can be put on the media
* out_len has the size of out_str when we are called.
* This routine will set out_len to actual bytes written to out_str.
* We make sure that we will not attempt to write beyond the out_str_len.
*/
{
out_str_len = *out_len;
return (ENAMETOOLONG);
}
*out_len = 0;
comp_id = 8;
goto end;
}
/*
* utf-8 characters can be
* of 1 - 6 bytes in length
*/
comp_id = 0x10;
}
}
goto end;
}
out_index = 0;
if (comp_id == 0x10) {
}
}
end:
}
return (error);
}
/*
* Take a utf16 character and convert
* it into a utf8 character.
* A 0 will be returned if the conversion fails
*/
{
/*
* Convert the 16-bit character to
* a 32-bit character
*/
/*
* By here the 16-bit character is converted
* to a 32-bit wide character
*/
if (c_32 < 0x80) {
nc = 1;
} else if (c_32 < 0x800) {
nc = 2;
} else if (c_32 < 0x10000) {
nc = 3;
} else if (c_32 < 0x200000) {
nc = 4;
} else if (c_32 < 0x4000000) {
nc = 5;
nc = 6;
} else {
nc = 0;
}
switch (nc) {
case 6 :
c_32 >>= 6;
/* FALLTHROUGH */
case 5 :
c_32 >>= 6;
/* FALLTHROUGH */
case 4 :
c_32 >>= 6;
/* FALLTHROUGH */
case 3 :
c_32 >>= 6;
/* FALLTHROUGH */
case 2 :
c_32 >>= 6;
/* FALLTHROUGH */
case 1 :
}
return (nc);
}
/*
* Convert to a form that can be transferred to the user
* Assumption's
* in_length < 256, out_str is at least 255 bytes long
* The converted byte stream length is returned in out_len
*/
#define MAX_ALLOWABLE_STRING 250
{
if (in_len == 0) {
*out_len = 0;
out_str[0] = '\0';
return (0);
}
*out_len = 0;
crc = 0;
/*
* File names "." and ".." are invalid under unix.
* Transform them into something
*/
if (comp_id == 8) {
len_till_now = 1;
goto make_append_crc;
}
} else if (comp_id == 0x10) {
len_till_now = 1;
goto make_append_crc;
}
} else {
*out_len = 0;
return (EINVAL);
}
/*
* Uncompress each character
*/
if (comp_id == 0x10) {
} else {
}
if (make_crc != 0) {
}
}
/*
* Get rid of invalid characters
*/
make_crc = 1;
if (((comp_id == 8) &&
(comp_id == 0x10) &&
} else {
continue;
}
}
/*
* Conver a 16bit character to a
* utf8 byte stream
*/
goto end;
}
/*
* The output string is larger than
* the maximum allowed string length
*/
if ((crc_start_loc == 0) &&
}
len_till_now += c_tx_sz;
} else {
break;
}
}
/*
* If we need to append CRC do it now
*/
if (make_crc) {
if (len_till_now > MAX_ALLOWABLE_STRING) {
}
if (dot_loc > 0) {
/*
* Make space for crc before the DOT
* move the rest of the file name to the end
*/
}
k = dot_loc;
} else {
k = len_till_now;
}
len_till_now += 5;
}
*out_len = len_till_now;
end:
return (error);
}
struct buf *
{
/*
* Buffer cache returned a
* wrong number of bytes
* flush the old buffer and
* reread it again
*/
} else {
}
goto begin;
}
return (bp);
}
/*
* Decide whether it is okay to remove within a sticky directory.
* Two conditions need to be met: write access to the directory
* is needed. In sticky directories, write access is not sufficient;
* you can remove entries from a directory only if you own the directory,
* if you are privileged, if you own the entry or if they entry is
* a plain file and you have write access to that file.
* Function returns 0 if remove access is granted.
*/
int
{
return (secpolicy_vnode_remove(cr));
return (0);
}