Skip to content

Commit ee703a7

Browse files
Zhao Mengmengjankara
authored andcommitted
udf: refactor udf_current_aext() to handle error
As Jan suggested in links below, refactor udf_current_aext() to differentiate between error, hit EOF and success, it now takes pointer to etype to store the extent type, return 1 when getting etype success, return 0 when hitting EOF and return -errno when err. Link: https://lore.kernel.org/all/20240912111235.6nr3wuqvktecy3vh@quack3/ Signed-off-by: Zhao Mengmeng <[email protected]> Suggested-by: Jan Kara <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 9852d85 commit ee703a7

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

fs/udf/inode.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,7 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
19531953
struct extent_position nepos;
19541954
struct kernel_lb_addr neloc;
19551955
int ver, adsize;
1956+
int err = 0;
19561957

19571958
if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
19581959
adsize = sizeof(struct short_ad);
@@ -1997,10 +1998,12 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
19971998
if (epos->offset + adsize > sb->s_blocksize) {
19981999
struct kernel_lb_addr cp_loc;
19992000
uint32_t cp_len;
2000-
int cp_type;
2001+
int8_t cp_type;
20012002

20022003
epos->offset -= adsize;
2003-
cp_type = udf_current_aext(inode, epos, &cp_loc, &cp_len, 0);
2004+
err = udf_current_aext(inode, epos, &cp_loc, &cp_len, &cp_type, 0);
2005+
if (err <= 0)
2006+
goto err_out;
20042007
cp_len |= ((uint32_t)cp_type) << 30;
20052008

20062009
__udf_add_aext(inode, &nepos, &cp_loc, cp_len, 1);
@@ -2015,6 +2018,9 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
20152018
*epos = nepos;
20162019

20172020
return 0;
2021+
err_out:
2022+
brelse(bh);
2023+
return err;
20182024
}
20192025

20202026
/*
@@ -2165,9 +2171,12 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
21652171
{
21662172
int8_t etype;
21672173
unsigned int indirections = 0;
2174+
int ret = 0;
21682175

2169-
while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
2170-
(EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) {
2176+
while ((ret = udf_current_aext(inode, epos, eloc, elen,
2177+
&etype, inc)) > 0) {
2178+
if (etype != (EXT_NEXT_EXTENT_ALLOCDESCS >> 30))
2179+
break;
21712180
udf_pblk_t block;
21722181

21732182
if (++indirections > UDF_MAX_INDIR_EXTS) {
@@ -2188,14 +2197,17 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
21882197
}
21892198
}
21902199

2191-
return etype;
2200+
return ret > 0 ? etype : -1;
21922201
}
21932202

2194-
int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
2195-
struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
2203+
/*
2204+
* Returns 1 on success, -errno on error, 0 on hit EOF.
2205+
*/
2206+
int udf_current_aext(struct inode *inode, struct extent_position *epos,
2207+
struct kernel_lb_addr *eloc, uint32_t *elen, int8_t *etype,
2208+
int inc)
21962209
{
21972210
int alen;
2198-
int8_t etype;
21992211
uint8_t *ptr;
22002212
struct short_ad *sad;
22012213
struct long_ad *lad;
@@ -2222,8 +2234,8 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
22222234
case ICBTAG_FLAG_AD_SHORT:
22232235
sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
22242236
if (!sad)
2225-
return -1;
2226-
etype = le32_to_cpu(sad->extLength) >> 30;
2237+
return 0;
2238+
*etype = le32_to_cpu(sad->extLength) >> 30;
22272239
eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
22282240
eloc->partitionReferenceNum =
22292241
iinfo->i_location.partitionReferenceNum;
@@ -2232,17 +2244,17 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
22322244
case ICBTAG_FLAG_AD_LONG:
22332245
lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
22342246
if (!lad)
2235-
return -1;
2236-
etype = le32_to_cpu(lad->extLength) >> 30;
2247+
return 0;
2248+
*etype = le32_to_cpu(lad->extLength) >> 30;
22372249
*eloc = lelb_to_cpu(lad->extLocation);
22382250
*elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
22392251
break;
22402252
default:
22412253
udf_debug("alloc_type = %u unsupported\n", iinfo->i_alloc_type);
2242-
return -1;
2254+
return -EINVAL;
22432255
}
22442256

2245-
return etype;
2257+
return 1;
22462258
}
22472259

22482260
static int udf_insert_aext(struct inode *inode, struct extent_position epos,

fs/udf/truncate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ int udf_truncate_extents(struct inode *inode)
188188
loff_t byte_offset;
189189
int adsize;
190190
struct udf_inode_info *iinfo = UDF_I(inode);
191+
int ret = 0;
191192

192193
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
193194
adsize = sizeof(struct short_ad);
@@ -217,8 +218,8 @@ int udf_truncate_extents(struct inode *inode)
217218
else
218219
lenalloc -= sizeof(struct allocExtDesc);
219220

220-
while ((etype = udf_current_aext(inode, &epos, &eloc,
221-
&elen, 0)) != -1) {
221+
while ((ret = udf_current_aext(inode, &epos, &eloc,
222+
&elen, &etype, 0)) > 0) {
222223
if (etype == (EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) {
223224
udf_write_aext(inode, &epos, &neloc, nelen, 0);
224225
if (indirect_ext_len) {
@@ -253,6 +254,11 @@ int udf_truncate_extents(struct inode *inode)
253254
}
254255
}
255256

257+
if (ret < 0) {
258+
brelse(epos.bh);
259+
return ret;
260+
}
261+
256262
if (indirect_ext_len) {
257263
BUG_ON(!epos.bh);
258264
udf_free_blocks(sb, NULL, &epos.block, 0, indirect_ext_len);

fs/udf/udfdecl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ extern void udf_write_aext(struct inode *, struct extent_position *,
171171
extern int8_t udf_delete_aext(struct inode *, struct extent_position);
172172
extern int8_t udf_next_aext(struct inode *, struct extent_position *,
173173
struct kernel_lb_addr *, uint32_t *, int);
174-
extern int8_t udf_current_aext(struct inode *, struct extent_position *,
175-
struct kernel_lb_addr *, uint32_t *, int);
174+
extern int udf_current_aext(struct inode *inode, struct extent_position *epos,
175+
struct kernel_lb_addr *eloc, uint32_t *elen,
176+
int8_t *etype, int inc);
176177
extern void udf_update_extra_perms(struct inode *inode, umode_t mode);
177178

178179
/* misc.c */

0 commit comments

Comments
 (0)