// SPDX-License-Identifier: GPL-2.0-only /* * linux/fs/isofs/inode.c * * (C) 1991 Linus Torvalds - minix filesystem * 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem. * 1994 Eberhard Mönkeberg - multi session handling. * 1995 Mark Dobie - allow mounting of some weird VideoCDs and PhotoCDs. * 1997 Gordon Chaffee - Joliet CDs * 1998 Eric Lammerts - ISO 9660 Level 3 * 2004 Paul Serice - Inode Support pushed out from 4GB to 128GB * 2004 Paul Serice - NFS Export Operations
*/
staticvoid destroy_inodecache(void)
{ /* * Make sure all delayed rcu free inodes are flushed before we * destroy cache.
*/
rcu_barrier();
kmem_cache_destroy(isofs_inode_cachep);
}
/* * Compute the hash for the isofs name corresponding to the dentry.
*/ staticint
isofs_hashi_common(conststruct dentry *dentry, struct qstr *qstr, int ms)
{ constchar *name; int len; char c; unsignedlong hash;
len = qstr->len;
name = qstr->name; if (ms) { while (len && name[len-1] == '.')
len--;
}
hash = init_name_hash(dentry); while (len--) {
c = tolower(*name++);
hash = partial_name_hash(c, hash);
}
qstr->hash = end_name_hash(hash);
return 0;
}
/* * Compare of two isofs names.
*/ staticint isofs_dentry_cmp_common( unsignedint len, constchar *str, conststruct qstr *name, int ms, int ci)
{ int alen, blen;
/* A filename cannot end in '.' or we treat it like it has none */
alen = name->len;
blen = len; if (ms) { while (alen && name->name[alen-1] == '.')
alen--; while (blen && str[blen-1] == '.')
blen--;
} if (alen == blen) { if (ci) { if (strncasecmp(name->name, str, alen) == 0) return 0;
} else { if (strncmp(name->name, str, alen) == 0) return 0;
}
} return 1;
}
#ifdef CONFIG_JOLIET /* * Compute the hash for the isofs name corresponding to the dentry.
*/ staticint
isofs_hash_common(conststruct dentry *dentry, struct qstr *qstr, int ms)
{ constchar *name; int len;
len = qstr->len;
name = qstr->name; if (ms) { while (len && name[len-1] == '.')
len--;
}
switch (opt) { case Opt_norock:
popt->rock = 0; break; case Opt_nojoliet:
popt->joliet = 0; break; case Opt_hide:
popt->hide = 1; break; case Opt_unhide: case Opt_showassoc:
popt->showassoc = 1; break; case Opt_cruft:
popt->cruft = 1; break; #ifdef CONFIG_JOLIET case Opt_utf8:
kfree(popt->iocharset);
popt->iocharset = kstrdup("utf8", GFP_KERNEL); if (!popt->iocharset) return -ENOMEM; break; case Opt_iocharset:
kfree(popt->iocharset);
popt->iocharset = kstrdup(param->string, GFP_KERNEL); if (!popt->iocharset) return -ENOMEM; break; #endif case Opt_map:
popt->map = result.uint_32; break; case Opt_session:
n = result.uint_32; /* * Track numbers are supposed to be in range 1-99, the * mount option starts indexing at 0.
*/ if (n >= 99) return -EINVAL;
popt->session = n + 1; break; case Opt_sb:
popt->sbsector = result.uint_32; break; case Opt_check:
popt->check = result.uint_32; break; case Opt_ignore: break; case Opt_uid:
popt->uid = result.uid;
popt->uid_set = 1; break; case Opt_gid:
popt->gid = result.gid;
popt->gid_set = 1; break; case Opt_mode:
popt->fmode = result.uint_32; break; case Opt_dmode:
popt->dmode = result.uint_32; break; case Opt_overriderockperm:
popt->overriderockperm = 1; break; case Opt_block:
n = result.uint_32; if (n != 512 && n != 1024 && n != 2048) return -EINVAL;
popt->blocksize = n; break; case Opt_nocompress:
popt->nocompress = 1; break; default: return -EINVAL;
} return 0;
}
/* * Display the mount options in /proc/mounts.
*/ staticint isofs_show_options(struct seq_file *m, struct dentry *root)
{ struct isofs_sb_info *sbi = ISOFS_SB(root->d_sb);
if (!sbi->s_rock) seq_puts(m, ",norock"); elseif (!sbi->s_joliet_level) seq_puts(m, ",nojoliet"); if (sbi->s_cruft) seq_puts(m, ",cruft"); if (sbi->s_hide) seq_puts(m, ",hide"); if (sbi->s_nocompress) seq_puts(m, ",nocompress"); if (sbi->s_overriderockperm) seq_puts(m, ",overriderockperm"); if (sbi->s_showassoc) seq_puts(m, ",showassoc");
if (sbi->s_check) seq_printf(m, ",check=%c", sbi->s_check); if (sbi->s_mapping) seq_printf(m, ",map=%c", sbi->s_mapping); if (sbi->s_session != 255) seq_printf(m, ",session=%u", sbi->s_session - 1); if (sbi->s_sbsector != -1) seq_printf(m, ",sbsector=%u", sbi->s_sbsector);
if (root->d_sb->s_blocksize != 1024)
seq_printf(m, ",blocksize=%lu", root->d_sb->s_blocksize);
if (sbi->s_uid_set)
seq_printf(m, ",uid=%u",
from_kuid_munged(&init_user_ns, sbi->s_uid)); if (sbi->s_gid_set)
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, sbi->s_gid));
if (sbi->s_dmode != ISOFS_INVALID_MODE)
seq_printf(m, ",dmode=%o", sbi->s_dmode); if (sbi->s_fmode != ISOFS_INVALID_MODE)
seq_printf(m, ",fmode=%o", sbi->s_fmode);
/* * look if the driver can tell the multi session redirection value * * don't change this if you don't know what you do, please! * Multisession is legal only with XA disks. * A non-XA disk with more than one volume descriptor may do it right, but * usually is written in a nowhere standardized "multi-partition" manner. * Multisession uses absolute addressing (solely the first frame of the whole * track is #0), multi-partition uses relative addressing (each first frame of * each track is #0), and a track is not a session. * * A broken CDwriter software or drive firmware does not set new standards, * at least not if conflicting with the existing ones. * * emoenke@gwdg.de
*/ #define WE_OBEY_THE_WRITTEN_STANDARDS 1
printk(KERN_ERR "ISOFS: Invalid session number or type of track\n");
}
if (cdi) { struct cdrom_multisession ms_info;
ms_info.addr_format = CDROM_LBA; if (cdrom_multisession(cdi, &ms_info) == 0) { #if WE_OBEY_THE_WRITTEN_STANDARDS /* necessary for a valid ms_info.addr */ if (ms_info.xa_flag) #endif
vol_desc_start = ms_info.addr.lba;
}
}
return vol_desc_start;
}
/* * Check if root directory is empty (has less than 3 files). * * Used to detect broken CDs where ISO root directory is empty but Joliet root * directory is OK. If such CD has Rock Ridge extensions, they will be disabled * (and Joliet used instead) or else no files would be visible.
*/ staticbool rootdir_empty(struct super_block *sb, unsignedlong block)
{ int offset = 0, files = 0, de_len; struct iso_directory_record *de; struct buffer_head *bh;
/* * First of all, get the hardware blocksize for this device. * If we don't know what it is, or the hardware blocksize is * larger than the blocksize the user specified, then use * that value.
*/ /* * What if bugger tells us to go beyond page size?
*/ if (bdev_logical_block_size(s->s_bdev) > 2048) {
printk(KERN_WARNING "ISOFS: unsupported/invalid hardware sector size %d\n",
bdev_logical_block_size(s->s_bdev)); goto out_freesbi;
}
opt->blocksize = sb_min_blocksize(s, opt->blocksize);
/* * Due to the overlapping physical location of the descriptors, * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure * proper identification in this case, we first check for ISO.
*/ if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) { if (isonum_711(vdp->type) == ISO_VD_END) break; if (isonum_711(vdp->type) == ISO_VD_PRIMARY) { if (!pri) {
pri = (struct iso_primary_descriptor *)vdp; /* Save the buffer in case we need it ... */
pri_bh = bh;
bh = NULL;
}
} #ifdef CONFIG_JOLIET elseif (isonum_711(vdp->type) == ISO_VD_SUPPLEMENTARY) {
sec = (struct iso_supplementary_descriptor *)vdp; if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) { if (opt->joliet) { if (sec->escape[2] == 0x40)
joliet_level = 1; elseif (sec->escape[2] == 0x43)
joliet_level = 2; elseif (sec->escape[2] == 0x45)
joliet_level = 3;
/* Just skip any volume descriptors we don't recognize */
brelse(bh);
bh = NULL;
} /* * If we fall through, either no volume descriptor was found, * or else we passed a primary descriptor looking for others.
*/ if (!pri) goto out_unknown_format;
brelse(bh);
bh = pri_bh;
pri_bh = NULL;
root_found: /* We don't support read-write mounts */ if (!sb_rdonly(s)) {
error = -EACCES; goto out_freebh;
}
if (joliet_level && (!pri || !opt->rock)) { /* This is the case of Joliet with the norock mount flag. * A disc with both Joliet and Rock Ridge is handled later
*/
pri = (struct iso_primary_descriptor *) sec;
}
sbi->s_ninodes = 0; /* No way to figure this out easily */
orig_zonesize = sbi->s_log_zone_size; /* * If the zone size is smaller than the hardware sector size, * this is a fatal error. This would occur if the disc drive * had sectors that were 2048 bytes, but the filesystem had * blocks that were 512 bytes (which should only very rarely * happen.)
*/ if (orig_zonesize < opt->blocksize) goto out_bad_size;
/* RDE: convert log zone size to bit shift */ switch (sbi->s_log_zone_size) { case 512: sbi->s_log_zone_size = 9; break; case 1024: sbi->s_log_zone_size = 10; break; case 2048: sbi->s_log_zone_size = 11; break;
default: goto out_bad_zone_size;
}
s->s_magic = ISOFS_SUPER_MAGIC;
/* * With multi-extent files, file size is only limited by the maximum * size of a file system, which is 8 TB.
*/
s->s_maxbytes = 0x80000000000LL;
/* Set this for reference. Its not currently used except on write
which we don't have .. */
first_data_zone = isonum_733(rootp->extent) +
isonum_711(rootp->ext_attr_length);
sbi->s_firstdatazone = first_data_zone; #ifndef BEQUIET
printk(KERN_DEBUG "ISOFS: Max size:%ld Log zone size:%ld\n",
sbi->s_max_size, 1UL << sbi->s_log_zone_size);
printk(KERN_DEBUG "ISOFS: First datazone:%ld\n", sbi->s_firstdatazone); if(sbi->s_high_sierra)
printk(KERN_DEBUG "ISOFS: Disc in High Sierra format.\n"); #endif
/* * If the Joliet level is set, we _may_ decide to use the * secondary descriptor, but can't be sure until after we * read the root inode. But before reading the root inode * we may need to change the device blocksize, and would * rather release the old buffer first. So, we cache the * first_data_zone value from the secondary descriptor.
*/ if (joliet_level) {
pri = (struct iso_primary_descriptor *) sec;
rootp = (struct iso_directory_record *)
pri->root_directory_record;
first_data_zone = isonum_733(rootp->extent) +
isonum_711(rootp->ext_attr_length);
}
/* * We're all done using the volume descriptor, and may need * to change the device blocksize, so release the buffer now.
*/
brelse(pri_bh);
brelse(bh);
/* * Force the blocksize to 512 for 512 byte sectors. The file * read primitives really get it wrong in a bad way if we don't * do this. * * Note - we should never be setting the blocksize to something * less than the hardware sector size for the device. If we * do, we would end up having to read larger buffers and split * out portions to satisfy requests. * * Note2- the idea here is that we want to deal with the optimal * zonesize in the filesystem. If we have it set to something less, * then we have horrible problems with trying to piece together * bits of adjacent blocks in order to properly read directory * entries. By forcing the blocksize in this way, we ensure * that we will never be required to do this.
*/
sb_set_blocksize(s, orig_zonesize);
sbi->s_nls_iocharset = NULL;
#ifdef CONFIG_JOLIET if (joliet_level) { char *p = opt->iocharset ? opt->iocharset : CONFIG_NLS_DEFAULT; if (strcmp(p, "utf8") != 0) {
sbi->s_nls_iocharset = opt->iocharset ?
load_nls(opt->iocharset) : load_nls_default(); if (!sbi->s_nls_iocharset) goto out_freesbi;
}
} #endif
s->s_op = &isofs_sops;
s->s_export_op = &isofs_export_ops;
sbi->s_mapping = opt->map;
sbi->s_rock = (opt->rock ? 2 : 0);
sbi->s_rock_offset = -1; /* initial offset, will guess until SP is found*/
sbi->s_cruft = opt->cruft;
sbi->s_hide = opt->hide;
sbi->s_showassoc = opt->showassoc;
sbi->s_uid = opt->uid;
sbi->s_gid = opt->gid;
sbi->s_uid_set = opt->uid_set;
sbi->s_gid_set = opt->gid_set;
sbi->s_nocompress = opt->nocompress;
sbi->s_overriderockperm = opt->overriderockperm; /* * It would be incredibly stupid to allow people to mark every file * on the disk as suid, so we merely allow them to set the default * permissions.
*/ if (opt->fmode != ISOFS_INVALID_MODE)
sbi->s_fmode = opt->fmode & 0777; else
sbi->s_fmode = ISOFS_INVALID_MODE; if (opt->dmode != ISOFS_INVALID_MODE)
sbi->s_dmode = opt->dmode & 0777; else
sbi->s_dmode = ISOFS_INVALID_MODE;
/* * Read the root inode, which _may_ result in changing * the s_rock flag. Once we have the final s_rock value, * we then decide whether to use the Joliet descriptor.
*/
inode = isofs_iget(s, sbi->s_firstdatazone, 0);
/* * Fix for broken CDs with a corrupt root inode but a correct Joliet * root directory.
*/ if (IS_ERR(inode)) { if (joliet_level && sbi->s_firstdatazone != first_data_zone) {
printk(KERN_NOTICE "ISOFS: root inode is unusable. " "Disabling Rock Ridge and switching to Joliet.");
sbi->s_rock = 0;
inode = NULL;
} else { goto out_no_root;
}
}
/* * Fix for broken CDs with Rock Ridge and empty ISO root directory but * correct Joliet root directory.
*/ if (sbi->s_rock == 1 && joliet_level &&
rootdir_empty(s, sbi->s_firstdatazone)) {
printk(KERN_NOTICE "ISOFS: primary root directory is empty. " "Disabling Rock Ridge and switching to Joliet.");
sbi->s_rock = 0;
}
/* * If this disk has both Rock Ridge and Joliet on it, then we * want to use Rock Ridge by default. This can be overridden * by using the norock mount option. There is still one other * possibility that is not taken into account: a Rock Ridge * CD with Unicode names. Until someone sees such a beast, it * will not be supported.
*/ if (sbi->s_rock == 1) {
joliet_level = 0;
} elseif (joliet_level) {
sbi->s_rock = 0; if (sbi->s_firstdatazone != first_data_zone) {
sbi->s_firstdatazone = first_data_zone;
printk(KERN_DEBUG "ISOFS: changing to secondary root\n");
iput(inode);
inode = isofs_iget(s, sbi->s_firstdatazone, 0); if (IS_ERR(inode)) goto out_no_root;
}
}
if (opt->check == 'u') { /* Only Joliet is case insensitive by default */ if (joliet_level)
opt->check = 'r'; else
opt->check = 's';
}
sbi->s_joliet_level = joliet_level;
/* Make sure the root inode is a directory */ if (!S_ISDIR(inode->i_mode)) {
printk(KERN_WARNING "isofs_fill_super: root inode is not a directory. " "Corrupted media?\n"); goto out_iput;
}
table = 0; if (joliet_level)
table += 2; if (opt->check == 'r')
table++;
sbi->s_check = opt->check;
if (table)
set_default_d_op(s, &isofs_dentry_ops[table - 1]);
/* get the root dentry */
s->s_root = d_make_root(inode); if (!(s->s_root)) {
error = -ENOMEM; goto out_no_inode;
}
/* * Get a set of blocks; filling in buffer_heads if already allocated * or getblk() if they are not. Returns the number of blocks inserted * (-ve == error.)
*/ int isofs_get_blocks(struct inode *inode, sector_t iblock, struct buffer_head **bh, unsignedlong nblocks)
{ unsignedlong b_off = iblock; unsigned offset, sect_size; unsignedint firstext; unsignedlong nextblk, nextoff; int section, rv, error; struct iso_inode_info *ei = ISOFS_I(inode);
error = -EIO;
rv = 0; if (iblock != b_off) {
printk(KERN_DEBUG "%s: block number too large\n", __func__); goto abort;
}
while (nblocks) { /* If we are *way* beyond the end of the file, print a message. * Access beyond the end of the file up to the next page boundary * is normal, however because of the way the page cache works. * In this case, we just return 0 so that we can properly fill * the page with useless information without generating any * I/O errors.
*/ if (b_off > ((inode->i_size + PAGE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) {
printk(KERN_DEBUG "%s: block >= EOF (%lu, %llu)\n",
__func__, b_off,
(unsignedlonglong)inode->i_size); goto abort;
}
/* On the last section, nextblk == 0, section size is likely to * exceed sect_size by a partial block, and access beyond the * end of the file will reach beyond the section size, too.
*/ while (nextblk && (b_off >= (offset + sect_size))) { struct inode *ninode;
if (*bh) {
map_bh(*bh, inode->i_sb, firstext + b_off - offset);
} else {
*bh = sb_getblk(inode->i_sb, firstext+b_off-offset); if (!*bh) goto abort;
}
bh++; /* Next buffer head */
b_off++; /* Next buffer offset */
nblocks--;
rv++;
}
error = 0;
abort: return rv != 0 ? rv : error;
}
/* * Used by the standard interfaces.
*/ staticint isofs_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
{ int ret;
if (create) {
printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__); return -EROFS;
}
ret = isofs_get_blocks(inode, iblock, &bh_result, 1); return ret < 0 ? ret : 0;
}
/* The first 16 blocks are reserved as the System Area. Thus, * no inodes can appear in block 0. We use this to flag that
* this is the last section. */
ei->i_next_section_block = 0;
ei->i_next_section_offset = 0;
/* Assume it is a normal-format file unless told otherwise */
ei->i_file_format = isofs_file_normal;
if (de->flags[-high_sierra] & 2) { if (sbi->s_dmode != ISOFS_INVALID_MODE)
inode->i_mode = S_IFDIR | sbi->s_dmode; else
inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
set_nlink(inode, 1); /* * Set to 1. We know there are 2, but * the find utility tries to optimize * if it is 2, and it screws up. It is * easier to give 1 which tells find to * do it the hard way.
*/
} else { if (sbi->s_fmode != ISOFS_INVALID_MODE) {
inode->i_mode = S_IFREG | sbi->s_fmode;
} else { /* * Set default permissions: r-x for all. The disc * could be shared with DOS machines so virtually * anything could be a valid executable.
*/
inode->i_mode = S_IFREG | S_IRUGO | S_IXUGO;
}
set_nlink(inode, 1);
}
inode->i_uid = sbi->s_uid;
inode->i_gid = sbi->s_gid;
inode->i_blocks = 0;
ei->i_section_size = isonum_733(de->size); if (de->flags[-high_sierra] & 0x80) {
ret = isofs_read_level3_size(inode); if (ret < 0) goto fail;
ret = -EIO;
} else {
ei->i_next_section_block = 0;
ei->i_next_section_offset = 0;
inode->i_size = isonum_733(de->size);
}
/* * Some dipshit decided to store some other bit of information * in the high byte of the file length. Truncate size in case * this CDROM was mounted with the cruft option.
*/
if (sbi->s_cruft)
inode->i_size &= 0x00ffffff;
if (de->interleave[0]) {
printk(KERN_DEBUG "ISOFS: Interleaved files not (yet) supported.\n");
inode->i_size = 0;
}
/* I have no idea what file_unit_size is used for, so
we will flag it for now */ if (de->file_unit_size[0] != 0) {
printk(KERN_DEBUG "ISOFS: File unit size != 0 for ISO file (%ld).\n",
inode->i_ino);
}
/* I have no idea what other flag bits are used for, so
we will flag it for now */ #ifdef DEBUG if((de->flags[-high_sierra] & ~2)!= 0){
printk(KERN_DEBUG "ISOFS: Unusual flag settings for ISO file " "(%ld %x).\n",
inode->i_ino, de->flags[-high_sierra]);
} #endif
ts = iso_date(de->date, high_sierra ? ISO_DATE_HIGH_SIERRA : 0);
inode_set_ctime_to_ts(inode, ts);
inode_set_atime_to_ts(inode, ts);
inode_set_mtime_to_ts(inode, ts);
/* Set the number of blocks for stat() - should be done before RR */
inode->i_blocks = (inode->i_size + 511) >> 9;
/* * Now test for possible Rock Ridge extensions which will override * some of these numbers in the inode structure.
*/
if (!high_sierra) {
parse_rock_ridge_inode(de, inode, relocated); /* if we want uid/gid set, override the rock ridge setting */ if (sbi->s_uid_set)
inode->i_uid = sbi->s_uid; if (sbi->s_gid_set)
inode->i_gid = sbi->s_gid;
} /* Now set final access rights if overriding rock ridge setting */ if (S_ISDIR(inode->i_mode) && sbi->s_overriderockperm &&
sbi->s_dmode != ISOFS_INVALID_MODE)
inode->i_mode = S_IFDIR | sbi->s_dmode; if (S_ISREG(inode->i_mode) && sbi->s_overriderockperm &&
sbi->s_fmode != ISOFS_INVALID_MODE)
inode->i_mode = S_IFREG | sbi->s_fmode;
/* Store, in the inode's containing structure, the block and block * offset that point to the underlying meta-data for the inode. The * code below is otherwise similar to the iget() code in
* include/linux/fs.h */ struct inode *__isofs_iget(struct super_block *sb, unsignedlong block, unsignedlong offset, int relocated)
{ unsignedlong hashval; struct inode *inode; struct isofs_iget5_callback_data data; long ret;
if (offset >= 1ul << sb->s_blocksize_bits) return ERR_PTR(-EINVAL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.