Lines Matching defs:fatent
44 static void fat12_ent_set_ptr(struct fat_entry *fatent, int offset)
46 struct buffer_head **bhs = fatent->bhs;
47 if (fatent->nr_bhs == 1) {
49 fatent->u.ent12_p[0] = bhs[0]->b_data + offset;
50 fatent->u.ent12_p[1] = bhs[0]->b_data + (offset + 1);
53 fatent->u.ent12_p[0] = bhs[0]->b_data + offset;
54 fatent->u.ent12_p[1] = bhs[1]->b_data;
58 static void fat16_ent_set_ptr(struct fat_entry *fatent, int offset)
61 fatent->u.ent16_p = (__le16 *)(fatent->bhs[0]->b_data + offset);
64 static void fat32_ent_set_ptr(struct fat_entry *fatent, int offset)
67 fatent->u.ent32_p = (__le32 *)(fatent->bhs[0]->b_data + offset);
70 static int fat12_ent_bread(struct super_block *sb, struct fat_entry *fatent,
73 struct buffer_head **bhs = fatent->bhs;
76 fatent->fat_inode = MSDOS_SB(sb)->fat_inode;
83 fatent->nr_bhs = 1;
90 fatent->nr_bhs = 2;
92 fat12_ent_set_ptr(fatent, offset);
102 static int fat_ent_bread(struct super_block *sb, struct fat_entry *fatent,
108 fatent->fat_inode = MSDOS_SB(sb)->fat_inode;
109 fatent->bhs[0] = sb_bread(sb, blocknr);
110 if (!fatent->bhs[0]) {
115 fatent->nr_bhs = 1;
116 ops->ent_set_ptr(fatent, offset);
120 static int fat12_ent_get(struct fat_entry *fatent)
122 u8 **ent12_p = fatent->u.ent12_p;
126 if (fatent->entry & 1)
138 static int fat16_ent_get(struct fat_entry *fatent)
140 int next = le16_to_cpu(*fatent->u.ent16_p);
141 WARN_ON((unsigned long)fatent->u.ent16_p & (2 - 1));
147 static int fat32_ent_get(struct fat_entry *fatent)
149 int next = le32_to_cpu(*fatent->u.ent32_p) & 0x0fffffff;
150 WARN_ON((unsigned long)fatent->u.ent32_p & (4 - 1));
156 static void fat12_ent_put(struct fat_entry *fatent, int new)
158 u8 **ent12_p = fatent->u.ent12_p;
164 if (fatent->entry & 1) {
173 mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
174 if (fatent->nr_bhs == 2)
175 mark_buffer_dirty_inode(fatent->bhs[1], fatent->fat_inode);
178 static void fat16_ent_put(struct fat_entry *fatent, int new)
183 *fatent->u.ent16_p = cpu_to_le16(new);
184 mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
187 static void fat32_ent_put(struct fat_entry *fatent, int new)
193 new |= le32_to_cpu(*fatent->u.ent32_p) & ~0x0fffffff;
194 *fatent->u.ent32_p = cpu_to_le32(new);
195 mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
198 static int fat12_ent_next(struct fat_entry *fatent)
200 u8 **ent12_p = fatent->u.ent12_p;
201 struct buffer_head **bhs = fatent->bhs;
202 u8 *nextp = ent12_p[1] + 1 + (fatent->entry & 1);
204 fatent->entry++;
205 if (fatent->nr_bhs == 1) {
220 fatent->nr_bhs = 1;
228 static int fat16_ent_next(struct fat_entry *fatent)
230 const struct buffer_head *bh = fatent->bhs[0];
231 fatent->entry++;
232 if (fatent->u.ent16_p < (__le16 *)(bh->b_data + (bh->b_size - 2))) {
233 fatent->u.ent16_p++;
236 fatent->u.ent16_p = NULL;
240 static int fat32_ent_next(struct fat_entry *fatent)
242 const struct buffer_head *bh = fatent->bhs[0];
243 fatent->entry++;
244 if (fatent->u.ent32_p < (__le32 *)(bh->b_data + (bh->b_size - 4))) {
245 fatent->u.ent32_p++;
248 fatent->u.ent32_p = NULL;
312 struct fat_entry *fatent,
317 struct buffer_head **bhs = fatent->bhs;
319 /* Is this fatent's blocks including this entry? */
320 if (!fatent->nr_bhs || bhs[0]->b_blocknr != blocknr)
325 if (fatent->nr_bhs == 2) {
327 fatent->nr_bhs = 1;
331 if (fatent->nr_bhs != 2)
337 ops->ent_set_ptr(fatent, offset);
341 int fat_ent_read(struct inode *inode, struct fat_entry *fatent, int entry)
350 fatent_brelse(fatent);
355 fatent_set_entry(fatent, entry);
358 if (!fat_ent_update_ptr(sb, fatent, offset, blocknr)) {
359 fatent_brelse(fatent);
360 err = ops->ent_bread(sb, fatent, offset, blocknr);
364 return ops->ent_get(fatent);
398 int fat_ent_write(struct inode *inode, struct fat_entry *fatent,
405 ops->ent_put(fatent, new);
407 err = fat_sync_bhs(fatent->bhs, fatent->nr_bhs);
411 return fat_mirror_bhs(sb, fatent->bhs, fatent->nr_bhs);
415 struct fat_entry *fatent)
417 if (sbi->fatent_ops->ent_next(fatent)) {
418 if (fatent->entry < sbi->max_cluster)
425 struct fat_entry *fatent)
431 fatent_brelse(fatent);
432 ops->ent_blocknr(sb, fatent->entry, &offset, &blocknr);
433 return ops->ent_bread(sb, fatent, offset, blocknr);
437 struct fat_entry *fatent)
441 for (n = 0; n < fatent->nr_bhs; n++) {
443 if (fatent->bhs[n] == bhs[i])
447 get_bh(fatent->bhs[n]);
448 bhs[i] = fatent->bhs[n];
459 struct fat_entry fatent, prev_ent;
475 fatent_init(&fatent);
476 fatent_set_entry(&fatent, sbi->prev_free + 1);
478 if (fatent.entry >= sbi->max_cluster)
479 fatent.entry = FAT_START_ENT;
480 fatent_set_entry(&fatent, fatent.entry);
481 err = fat_ent_read_block(sb, &fatent);
487 if (ops->ent_get(&fatent) == FAT_ENT_FREE) {
488 int entry = fatent.entry;
491 ops->ent_put(&fatent, FAT_ENT_EOF);
495 fat_collect_bhs(bhs, &nr_bhs, &fatent);
511 prev_ent = fatent;
516 } while (fat_ent_next(sbi, &fatent));
527 fatent_brelse(&fatent);
548 struct fat_entry fatent;
554 fatent_init(&fatent);
557 cluster = fat_ent_read(inode, &fatent, cluster);
574 if (cluster != fatent.entry + 1) {
575 int nr_clus = fatent.entry - first_cl + 1;
585 ops->ent_put(&fatent, FAT_ENT_FREE);
591 if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) {
604 fat_collect_bhs(bhs, &nr_bhs, &fatent);
614 fatent_brelse(&fatent);
627 static void fat_ent_reada(struct super_block *sb, struct fat_entry *fatent,
634 ops->ent_blocknr(sb, fatent->entry, &offset, &blocknr);
644 struct fat_entry fatent;
657 fatent_init(&fatent);
658 fatent_set_entry(&fatent, FAT_START_ENT);
659 while (fatent.entry < sbi->max_cluster) {
663 fat_ent_reada(sb, &fatent, min(reada_blocks, rest));
667 err = fat_ent_read_block(sb, &fatent);
672 if (ops->ent_get(&fatent) == FAT_ENT_FREE)
674 } while (fat_ent_next(sbi, &fatent));
679 fatent_brelse(&fatent);