^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * directory.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Directory related functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file is distributed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * License (GPL). Copies of the GPL can be obtained from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * ftp://prep.ai.mit.edu/pub/gnu/GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Each contributing author retains all rights to their own work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "udfdecl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "udf_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct udf_fileident_bh *fibh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct fileIdentDesc *cfi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct extent_position *epos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct kernel_lb_addr *eloc, uint32_t *elen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) sector_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct fileIdentDesc *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int i, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) udf_pblk_t block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct buffer_head *tmp, *bha[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct udf_inode_info *iinfo = UDF_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) fibh->soffset = fibh->eoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) fi = udf_get_fileident(iinfo->i_data -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) (iinfo->i_efe ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) sizeof(struct extendedFileEntry) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) sizeof(struct fileEntry)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) dir->i_sb->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) &(fibh->eoffset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (!fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *nf_pos += fibh->eoffset - fibh->soffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) memcpy((uint8_t *)cfi, (uint8_t *)fi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) sizeof(struct fileIdentDesc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (fibh->eoffset == dir->i_sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) uint32_t lextoffset = epos->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (udf_next_aext(dir, epos, eloc, elen, 1) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) (EXT_RECORDED_ALLOCATED >> 30))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) block = udf_get_lb_pblock(dir->i_sb, eloc, *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) (*offset)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if ((*offset << blocksize_bits) >= *elen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) epos->offset = lextoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) brelse(fibh->sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (!fibh->sbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) fibh->soffset = fibh->eoffset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) i = 16 >> (blocksize_bits - 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (i + *offset > (*elen >> blocksize_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) i = (*elen >> blocksize_bits)-*offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) for (num = 0; i > 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) block = udf_get_lb_pblock(dir->i_sb, eloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *offset + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) tmp = udf_tgetblk(dir->i_sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (tmp && !buffer_uptodate(tmp) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) !buffer_locked(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bha[num++] = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) brelse(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ll_rw_block(REQ_OP_READ, REQ_RAHEAD, num, bha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) brelse(bha[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else if (fibh->sbh != fibh->ebh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) brelse(fibh->sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) fibh->sbh = fibh->ebh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) &(fibh->eoffset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *nf_pos += fibh->eoffset - fibh->soffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (fibh->eoffset <= dir->i_sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) memcpy((uint8_t *)cfi, (uint8_t *)fi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) sizeof(struct fileIdentDesc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } else if (fibh->eoffset > dir->i_sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) uint32_t lextoffset = epos->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (udf_next_aext(dir, epos, eloc, elen, 1) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) (EXT_RECORDED_ALLOCATED >> 30))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) block = udf_get_lb_pblock(dir->i_sb, eloc, *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) (*offset)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) epos->offset = lextoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) fibh->soffset -= dir->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) fibh->eoffset -= dir->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) fibh->ebh = udf_tread(dir->i_sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!fibh->ebh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int fi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) memcpy((uint8_t *)cfi - fibh->soffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) fibh->ebh->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sizeof(struct fileIdentDesc) + fibh->soffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) fi_len = udf_dir_entry_len(cfi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) *nf_pos += fi_len - (fibh->eoffset - fibh->soffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) fibh->eoffset = fibh->soffset + fi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) memcpy((uint8_t *)cfi, (uint8_t *)fi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sizeof(struct fileIdentDesc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Got last entry outside of dir size - fs is corrupted! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (*nf_pos > dir->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct fileIdentDesc *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int lengthThisIdent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) uint8_t *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int padlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if ((!buffer) || (!offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) udf_debug("invalidparms, buffer=%p, offset=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) buffer, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ptr = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if ((*offset > 0) && (*offset < bufsize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ptr += *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) fi = (struct fileIdentDesc *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) udf_debug("0x%x != TAG_IDENT_FID\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) le16_to_cpu(fi->descTag.tagIdent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) udf_debug("offset: %d sizeof: %lu bufsize: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *offset, (unsigned long)sizeof(struct fileIdentDesc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) lengthThisIdent = sizeof(struct fileIdentDesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) lengthThisIdent = sizeof(struct fileIdentDesc) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* we need to figure padding, too! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) padlen = lengthThisIdent % UDF_NAME_PAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (padlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) lengthThisIdent += (UDF_NAME_PAD - padlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *offset = *offset + lengthThisIdent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct short_ad *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if ((!ptr) || (!offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pr_err("%s: invalidparms\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if ((*offset + sizeof(struct short_ad)) > maxoffset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) sa = (struct short_ad *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (sa->extLength == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *offset += sizeof(struct short_ad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct long_ad *la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if ((!ptr) || (!offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pr_err("%s: invalidparms\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if ((*offset + sizeof(struct long_ad)) > maxoffset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) la = (struct long_ad *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (la->extLength == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *offset += sizeof(struct long_ad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }