Blame view
fs/udf/dir.c
5.37 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 |
/* * dir.c * * PURPOSE * Directory handling routines for the OSTA-UDF(tm) filesystem. * |
1da177e4c Linux-2.6.12-rc2 |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
* COPYRIGHT * This file is distributed under the terms of the GNU General Public * License (GPL). Copies of the GPL can be obtained from: * ftp://prep.ai.mit.edu/pub/gnu/GPL * Each contributing author retains all rights to their own work. * * (C) 1998-2004 Ben Fennema * * HISTORY * * 10/05/98 dgb Split directory operations into its own file * Implemented directory reads via do_udf_readdir * 10/06/98 Made directory operations work! * 11/17/98 Rewrote directory to support ICBTAG_FLAG_AD_LONG * 11/25/98 blf Rewrote directory handling (readdir+lookup) to support reading * across blocks. * 12/12/98 Split out the lookup code to namei.c. bulk of directory * code now in directory.c:udf_fileident_read. */ #include "udfdecl.h" #include <linux/string.h> #include <linux/errno.h> #include <linux/mm.h> #include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
33 34 35 36 |
#include <linux/buffer_head.h> #include "udf_i.h" #include "udf_sb.h" |
934c5e601 udf: remove wrong... |
37 38 |
static int do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir, void *dirent) |
1da177e4c Linux-2.6.12-rc2 |
39 |
{ |
b80697c14 udf: Remove decla... |
40 |
struct udf_fileident_bh fibh = { .sbh = NULL, .ebh = NULL}; |
cb00ea352 UDF: coding style... |
41 |
struct fileIdentDesc *fi = NULL; |
1da177e4c Linux-2.6.12-rc2 |
42 43 |
struct fileIdentDesc cfi; int block, iblock; |
e28d80f18 udf: fix director... |
44 |
loff_t nf_pos = (filp->f_pos - 1) << 2; |
1da177e4c Linux-2.6.12-rc2 |
45 |
int flen; |
391e8bbd3 sanitize const/si... |
46 47 |
unsigned char *fname = NULL; unsigned char *nameptr; |
1da177e4c Linux-2.6.12-rc2 |
48 49 |
uint16_t liu; uint8_t lfi; |
e28d80f18 udf: fix director... |
50 |
loff_t size = udf_ext0_offset(dir) + dir->i_size; |
ff116fc8d UDF: introduce st... |
51 |
struct buffer_head *tmp, *bha[16]; |
5ca4e4be8 Remove struct typ... |
52 |
struct kernel_lb_addr eloc; |
ff116fc8d UDF: introduce st... |
53 |
uint32_t elen; |
60448b1d6 udf: use sector_t... |
54 |
sector_t offset; |
b80697c14 udf: Remove decla... |
55 |
int i, num, ret = 0; |
1da177e4c Linux-2.6.12-rc2 |
56 |
unsigned int dt_type; |
cb00ea352 UDF: coding style... |
57 |
struct extent_position epos = { NULL, 0, {0, 0} }; |
48d6d8ff7 udf: cache struct... |
58 |
struct udf_inode_info *iinfo; |
1da177e4c Linux-2.6.12-rc2 |
59 60 |
if (nf_pos >= size) |
b80697c14 udf: Remove decla... |
61 62 63 64 65 66 67 |
goto out; fname = kmalloc(UDF_NAME_LEN, GFP_NOFS); if (!fname) { ret = -ENOMEM; goto out; } |
1da177e4c Linux-2.6.12-rc2 |
68 69 |
if (nf_pos == 0) |
e28d80f18 udf: fix director... |
70 |
nf_pos = udf_ext0_offset(dir); |
1da177e4c Linux-2.6.12-rc2 |
71 |
|
e28d80f18 udf: fix director... |
72 |
fibh.soffset = fibh.eoffset = nf_pos & (dir->i_sb->s_blocksize - 1); |
48d6d8ff7 udf: cache struct... |
73 |
iinfo = UDF_I(dir); |
b80697c14 udf: Remove decla... |
74 75 76 77 78 79 80 |
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { if (inode_bmap(dir, nf_pos >> dir->i_sb->s_blocksize_bits, &epos, &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) { ret = -ENOENT; goto out; } |
97e961fdb Fix the udf code ... |
81 |
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset); |
cb00ea352 UDF: coding style... |
82 |
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
48d6d8ff7 udf: cache struct... |
83 |
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
5ca4e4be8 Remove struct typ... |
84 |
epos.offset -= sizeof(struct short_ad); |
48d6d8ff7 udf: cache struct... |
85 |
else if (iinfo->i_alloc_type == |
c0b344385 udf: remove UDF_I... |
86 |
ICBTAG_FLAG_AD_LONG) |
5ca4e4be8 Remove struct typ... |
87 |
epos.offset -= sizeof(struct long_ad); |
28de7948a UDF: coding style... |
88 |
} else { |
1da177e4c Linux-2.6.12-rc2 |
89 |
offset = 0; |
28de7948a UDF: coding style... |
90 |
} |
1da177e4c Linux-2.6.12-rc2 |
91 |
|
cb00ea352 UDF: coding style... |
92 |
if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { |
b80697c14 udf: Remove decla... |
93 94 |
ret = -EIO; goto out; |
1da177e4c Linux-2.6.12-rc2 |
95 |
} |
cb00ea352 UDF: coding style... |
96 97 |
if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { |
1da177e4c Linux-2.6.12-rc2 |
98 |
i = 16 >> (dir->i_sb->s_blocksize_bits - 9); |
cb00ea352 UDF: coding style... |
99 |
if (i + offset > (elen >> dir->i_sb->s_blocksize_bits)) |
28de7948a UDF: coding style... |
100 |
i = (elen >> dir->i_sb->s_blocksize_bits) - offset; |
cb00ea352 UDF: coding style... |
101 |
for (num = 0; i > 0; i--) { |
97e961fdb Fix the udf code ... |
102 |
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset + i); |
1da177e4c Linux-2.6.12-rc2 |
103 |
tmp = udf_tgetblk(dir->i_sb, block); |
28de7948a UDF: coding style... |
104 |
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) |
1da177e4c Linux-2.6.12-rc2 |
105 106 107 108 |
bha[num++] = tmp; else brelse(tmp); } |
cb00ea352 UDF: coding style... |
109 |
if (num) { |
1da177e4c Linux-2.6.12-rc2 |
110 |
ll_rw_block(READA, num, bha); |
cb00ea352 UDF: coding style... |
111 |
for (i = 0; i < num; i++) |
1da177e4c Linux-2.6.12-rc2 |
112 113 114 |
brelse(bha[i]); } } |
1da177e4c Linux-2.6.12-rc2 |
115 |
} |
cb00ea352 UDF: coding style... |
116 |
while (nf_pos < size) { |
e28d80f18 udf: fix director... |
117 |
filp->f_pos = (nf_pos >> 2) + 1; |
1da177e4c Linux-2.6.12-rc2 |
118 |
|
cb00ea352 UDF: coding style... |
119 120 |
fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset); |
b80697c14 udf: Remove decla... |
121 122 |
if (!fi) goto out; |
1da177e4c Linux-2.6.12-rc2 |
123 124 125 |
liu = le16_to_cpu(cfi.lengthOfImpUse); lfi = cfi.lengthFileIdent; |
28de7948a UDF: coding style... |
126 |
if (fibh.sbh == fibh.ebh) { |
1da177e4c Linux-2.6.12-rc2 |
127 |
nameptr = fi->fileIdent + liu; |
28de7948a UDF: coding style... |
128 |
} else { |
1da177e4c Linux-2.6.12-rc2 |
129 |
int poffset; /* Unpaded ending offset */ |
28de7948a UDF: coding style... |
130 |
poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi; |
1da177e4c Linux-2.6.12-rc2 |
131 |
|
28de7948a UDF: coding style... |
132 133 134 |
if (poffset >= lfi) { nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); } else { |
1da177e4c Linux-2.6.12-rc2 |
135 |
nameptr = fname; |
cb00ea352 UDF: coding style... |
136 137 138 139 |
memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); memcpy(nameptr + lfi - poffset, fibh.ebh->b_data, poffset); |
1da177e4c Linux-2.6.12-rc2 |
140 141 |
} } |
cb00ea352 UDF: coding style... |
142 143 |
if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE)) |
1da177e4c Linux-2.6.12-rc2 |
144 145 |
continue; } |
cb00ea352 UDF: coding style... |
146 147 148 |
if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE)) |
1da177e4c Linux-2.6.12-rc2 |
149 150 |
continue; } |
cb00ea352 UDF: coding style... |
151 |
if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) { |
5096e933a [PATCH] struct pa... |
152 |
iblock = parent_ino(filp->f_path.dentry); |
1da177e4c Linux-2.6.12-rc2 |
153 154 155 |
flen = 2; memcpy(fname, "..", flen); dt_type = DT_DIR; |
cb00ea352 UDF: coding style... |
156 |
} else { |
5ca4e4be8 Remove struct typ... |
157 |
struct kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation); |
1da177e4c Linux-2.6.12-rc2 |
158 |
|
97e961fdb Fix the udf code ... |
159 |
iblock = udf_get_lb_pblock(dir->i_sb, &tloc, 0); |
1da177e4c Linux-2.6.12-rc2 |
160 161 162 |
flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); dt_type = DT_UNKNOWN; } |
b80697c14 udf: Remove decla... |
163 164 165 |
if (flen && filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0) goto out; |
28de7948a UDF: coding style... |
166 |
} /* end while */ |
1da177e4c Linux-2.6.12-rc2 |
167 |
|
e28d80f18 udf: fix director... |
168 |
filp->f_pos = (nf_pos >> 2) + 1; |
1da177e4c Linux-2.6.12-rc2 |
169 |
|
b80697c14 udf: Remove decla... |
170 |
out: |
1da177e4c Linux-2.6.12-rc2 |
171 |
if (fibh.sbh != fibh.ebh) |
3bf25cb40 udf: use get_bh() |
172 173 174 |
brelse(fibh.ebh); brelse(fibh.sbh); brelse(epos.bh); |
b80697c14 udf: Remove decla... |
175 |
kfree(fname); |
1da177e4c Linux-2.6.12-rc2 |
176 |
|
b80697c14 udf: Remove decla... |
177 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
178 |
} |
934c5e601 udf: remove wrong... |
179 |
|
934c5e601 udf: remove wrong... |
180 181 182 183 |
static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) { struct inode *dir = filp->f_path.dentry->d_inode; int result; |
934c5e601 udf: remove wrong... |
184 185 |
if (filp->f_pos == 0) { if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) { |
934c5e601 udf: remove wrong... |
186 187 188 189 190 191 |
return 0; } filp->f_pos++; } result = do_udf_readdir(dir, filp, filldir, dirent); |
934c5e601 udf: remove wrong... |
192 193 194 195 196 |
return result; } /* readdir and lookup functions */ const struct file_operations udf_dir_operations = { |
ca572727d fs/: do not fallb... |
197 |
.llseek = generic_file_llseek, |
934c5e601 udf: remove wrong... |
198 199 |
.read = generic_read_dir, .readdir = udf_readdir, |
2f07a88b3 udf: BKL ioctl pu... |
200 |
.unlocked_ioctl = udf_ioctl, |
1b061d924 rename the generi... |
201 |
.fsync = generic_file_fsync, |
934c5e601 udf: remove wrong... |
202 |
}; |