~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/ufs/inode.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/ufs/inode.c (Version linux-6.11.5) and /fs/ufs/inode.c (Version linux-4.9.337)


  1 // SPDX-License-Identifier: GPL-2.0            << 
  2 /*                                                  1 /*
  3  *  linux/fs/ufs/inode.c                            2  *  linux/fs/ufs/inode.c
  4  *                                                  3  *
  5  * Copyright (C) 1998                               4  * Copyright (C) 1998
  6  * Daniel Pirkl <daniel.pirkl@email.cz>             5  * Daniel Pirkl <daniel.pirkl@email.cz>
  7  * Charles University, Faculty of Mathematics       6  * Charles University, Faculty of Mathematics and Physics
  8  *                                                  7  *
  9  *  from                                            8  *  from
 10  *                                                  9  *
 11  *  linux/fs/ext2/inode.c                          10  *  linux/fs/ext2/inode.c
 12  *                                                 11  *
 13  * Copyright (C) 1992, 1993, 1994, 1995            12  * Copyright (C) 1992, 1993, 1994, 1995
 14  * Remy Card (card@masi.ibp.fr)                    13  * Remy Card (card@masi.ibp.fr)
 15  * Laboratoire MASI - Institut Blaise Pascal       14  * Laboratoire MASI - Institut Blaise Pascal
 16  * Universite Pierre et Marie Curie (Paris VI)     15  * Universite Pierre et Marie Curie (Paris VI)
 17  *                                                 16  *
 18  *  from                                           17  *  from
 19  *                                                 18  *
 20  *  linux/fs/minix/inode.c                         19  *  linux/fs/minix/inode.c
 21  *                                                 20  *
 22  *  Copyright (C) 1991, 1992  Linus Torvalds       21  *  Copyright (C) 1991, 1992  Linus Torvalds
 23  *                                                 22  *
 24  *  Goal-directed block allocation by Stephen      23  *  Goal-directed block allocation by Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
 25  *  Big-endian to little-endian byte-swapping/     24  *  Big-endian to little-endian byte-swapping/bitmaps by
 26  *        David S. Miller (davem@caip.rutgers.     25  *        David S. Miller (davem@caip.rutgers.edu), 1995
 27  */                                                26  */
 28                                                    27 
 29 #include <linux/uaccess.h>                     !!  28 #include <asm/uaccess.h>
 30                                                    29 
 31 #include <linux/errno.h>                           30 #include <linux/errno.h>
 32 #include <linux/fs.h>                              31 #include <linux/fs.h>
 33 #include <linux/time.h>                            32 #include <linux/time.h>
 34 #include <linux/stat.h>                            33 #include <linux/stat.h>
 35 #include <linux/string.h>                          34 #include <linux/string.h>
 36 #include <linux/mm.h>                              35 #include <linux/mm.h>
 37 #include <linux/buffer_head.h>                     36 #include <linux/buffer_head.h>
 38 #include <linux/mpage.h>                       << 
 39 #include <linux/writeback.h>                       37 #include <linux/writeback.h>
 40 #include <linux/iversion.h>                    << 
 41                                                    38 
 42 #include "ufs_fs.h"                                39 #include "ufs_fs.h"
 43 #include "ufs.h"                                   40 #include "ufs.h"
 44 #include "swab.h"                                  41 #include "swab.h"
 45 #include "util.h"                                  42 #include "util.h"
 46                                                    43 
 47 static int ufs_block_to_path(struct inode *ino     44 static int ufs_block_to_path(struct inode *inode, sector_t i_block, unsigned offsets[4])
 48 {                                                  45 {
 49         struct ufs_sb_private_info *uspi = UFS     46         struct ufs_sb_private_info *uspi = UFS_SB(inode->i_sb)->s_uspi;
 50         int ptrs = uspi->s_apb;                    47         int ptrs = uspi->s_apb;
 51         int ptrs_bits = uspi->s_apbshift;          48         int ptrs_bits = uspi->s_apbshift;
 52         const long direct_blocks = UFS_NDADDR,     49         const long direct_blocks = UFS_NDADDR,
 53                 indirect_blocks = ptrs,            50                 indirect_blocks = ptrs,
 54                 double_blocks = (1 << (ptrs_bi     51                 double_blocks = (1 << (ptrs_bits * 2));
 55         int n = 0;                                 52         int n = 0;
 56                                                    53 
 57                                                    54 
 58         UFSD("ptrs=uspi->s_apb = %d,double_blo     55         UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
 59         if (i_block < direct_blocks) {             56         if (i_block < direct_blocks) {
 60                 offsets[n++] = i_block;            57                 offsets[n++] = i_block;
 61         } else if ((i_block -= direct_blocks)      58         } else if ((i_block -= direct_blocks) < indirect_blocks) {
 62                 offsets[n++] = UFS_IND_BLOCK;      59                 offsets[n++] = UFS_IND_BLOCK;
 63                 offsets[n++] = i_block;            60                 offsets[n++] = i_block;
 64         } else if ((i_block -= indirect_blocks     61         } else if ((i_block -= indirect_blocks) < double_blocks) {
 65                 offsets[n++] = UFS_DIND_BLOCK;     62                 offsets[n++] = UFS_DIND_BLOCK;
 66                 offsets[n++] = i_block >> ptrs     63                 offsets[n++] = i_block >> ptrs_bits;
 67                 offsets[n++] = i_block & (ptrs     64                 offsets[n++] = i_block & (ptrs - 1);
 68         } else if (((i_block -= double_blocks)     65         } else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
 69                 offsets[n++] = UFS_TIND_BLOCK;     66                 offsets[n++] = UFS_TIND_BLOCK;
 70                 offsets[n++] = i_block >> (ptr     67                 offsets[n++] = i_block >> (ptrs_bits * 2);
 71                 offsets[n++] = (i_block >> ptr     68                 offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
 72                 offsets[n++] = i_block & (ptrs     69                 offsets[n++] = i_block & (ptrs - 1);
 73         } else {                                   70         } else {
 74                 ufs_warning(inode->i_sb, "ufs_     71                 ufs_warning(inode->i_sb, "ufs_block_to_path", "block > big");
 75         }                                          72         }
 76         return n;                                  73         return n;
 77 }                                                  74 }
 78                                                    75 
 79 typedef struct {                                   76 typedef struct {
 80         void    *p;                                77         void    *p;
 81         union {                                    78         union {
 82                 __fs32  key32;                     79                 __fs32  key32;
 83                 __fs64  key64;                     80                 __fs64  key64;
 84         };                                         81         };
 85         struct buffer_head *bh;                    82         struct buffer_head *bh;
 86 } Indirect;                                        83 } Indirect;
 87                                                    84 
 88 static inline int grow_chain32(struct ufs_inod     85 static inline int grow_chain32(struct ufs_inode_info *ufsi,
 89                                struct buffer_h     86                                struct buffer_head *bh, __fs32 *v,
 90                                Indirect *from,     87                                Indirect *from, Indirect *to)
 91 {                                                  88 {
 92         Indirect *p;                               89         Indirect *p;
 93         unsigned seq;                              90         unsigned seq;
 94         to->bh = bh;                               91         to->bh = bh;
 95         do {                                       92         do {
 96                 seq = read_seqbegin(&ufsi->met     93                 seq = read_seqbegin(&ufsi->meta_lock);
 97                 to->key32 = *(__fs32 *)(to->p      94                 to->key32 = *(__fs32 *)(to->p = v);
 98                 for (p = from; p <= to && p->k     95                 for (p = from; p <= to && p->key32 == *(__fs32 *)p->p; p++)
 99                         ;                          96                         ;
100         } while (read_seqretry(&ufsi->meta_loc     97         } while (read_seqretry(&ufsi->meta_lock, seq));
101         return (p > to);                           98         return (p > to);
102 }                                                  99 }
103                                                   100 
104 static inline int grow_chain64(struct ufs_inod    101 static inline int grow_chain64(struct ufs_inode_info *ufsi,
105                                struct buffer_h    102                                struct buffer_head *bh, __fs64 *v,
106                                Indirect *from,    103                                Indirect *from, Indirect *to)
107 {                                                 104 {
108         Indirect *p;                              105         Indirect *p;
109         unsigned seq;                             106         unsigned seq;
110         to->bh = bh;                              107         to->bh = bh;
111         do {                                      108         do {
112                 seq = read_seqbegin(&ufsi->met    109                 seq = read_seqbegin(&ufsi->meta_lock);
113                 to->key64 = *(__fs64 *)(to->p     110                 to->key64 = *(__fs64 *)(to->p = v);
114                 for (p = from; p <= to && p->k    111                 for (p = from; p <= to && p->key64 == *(__fs64 *)p->p; p++)
115                         ;                         112                         ;
116         } while (read_seqretry(&ufsi->meta_loc    113         } while (read_seqretry(&ufsi->meta_lock, seq));
117         return (p > to);                          114         return (p > to);
118 }                                                 115 }
119                                                   116 
120 /*                                                117 /*
121  * Returns the location of the fragment from      118  * Returns the location of the fragment from
122  * the beginning of the filesystem.               119  * the beginning of the filesystem.
123  */                                               120  */
124                                                   121 
125 static u64 ufs_frag_map(struct inode *inode, u    122 static u64 ufs_frag_map(struct inode *inode, unsigned offsets[4], int depth)
126 {                                                 123 {
127         struct ufs_inode_info *ufsi = UFS_I(in    124         struct ufs_inode_info *ufsi = UFS_I(inode);
128         struct super_block *sb = inode->i_sb;     125         struct super_block *sb = inode->i_sb;
129         struct ufs_sb_private_info *uspi = UFS    126         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
130         u64 mask = (u64) uspi->s_apbmask>>uspi    127         u64 mask = (u64) uspi->s_apbmask>>uspi->s_fpbshift;
131         int shift = uspi->s_apbshift-uspi->s_f    128         int shift = uspi->s_apbshift-uspi->s_fpbshift;
132         Indirect chain[4], *q = chain;            129         Indirect chain[4], *q = chain;
133         unsigned *p;                              130         unsigned *p;
134         unsigned flags = UFS_SB(sb)->s_flags;     131         unsigned flags = UFS_SB(sb)->s_flags;
135         u64 res = 0;                              132         u64 res = 0;
136                                                   133 
137         UFSD(": uspi->s_fpbshift = %d ,uspi->s    134         UFSD(": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",
138                 uspi->s_fpbshift, uspi->s_apbm    135                 uspi->s_fpbshift, uspi->s_apbmask,
139                 (unsigned long long)mask);        136                 (unsigned long long)mask);
140                                                   137 
141         if (depth == 0)                           138         if (depth == 0)
142                 goto no_block;                    139                 goto no_block;
143                                                   140 
144 again:                                            141 again:
145         p = offsets;                              142         p = offsets;
146                                                   143 
147         if ((flags & UFS_TYPE_MASK) == UFS_TYP    144         if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
148                 goto ufs2;                        145                 goto ufs2;
149                                                   146 
150         if (!grow_chain32(ufsi, NULL, &ufsi->i    147         if (!grow_chain32(ufsi, NULL, &ufsi->i_u1.i_data[*p++], chain, q))
151                 goto changed;                     148                 goto changed;
152         if (!q->key32)                            149         if (!q->key32)
153                 goto no_block;                    150                 goto no_block;
154         while (--depth) {                         151         while (--depth) {
155                 __fs32 *ptr;                      152                 __fs32 *ptr;
156                 struct buffer_head *bh;           153                 struct buffer_head *bh;
157                 unsigned n = *p++;                154                 unsigned n = *p++;
158                                                   155 
159                 bh = sb_bread(sb, uspi->s_sbba    156                 bh = sb_bread(sb, uspi->s_sbbase +
160                                   fs32_to_cpu(    157                                   fs32_to_cpu(sb, q->key32) + (n>>shift));
161                 if (!bh)                          158                 if (!bh)
162                         goto no_block;            159                         goto no_block;
163                 ptr = (__fs32 *)bh->b_data + (    160                 ptr = (__fs32 *)bh->b_data + (n & mask);
164                 if (!grow_chain32(ufsi, bh, pt    161                 if (!grow_chain32(ufsi, bh, ptr, chain, ++q))
165                         goto changed;             162                         goto changed;
166                 if (!q->key32)                    163                 if (!q->key32)
167                         goto no_block;            164                         goto no_block;
168         }                                         165         }
169         res = fs32_to_cpu(sb, q->key32);          166         res = fs32_to_cpu(sb, q->key32);
170         goto found;                               167         goto found;
171                                                   168 
172 ufs2:                                             169 ufs2:
173         if (!grow_chain64(ufsi, NULL, &ufsi->i    170         if (!grow_chain64(ufsi, NULL, &ufsi->i_u1.u2_i_data[*p++], chain, q))
174                 goto changed;                     171                 goto changed;
175         if (!q->key64)                            172         if (!q->key64)
176                 goto no_block;                    173                 goto no_block;
177                                                   174 
178         while (--depth) {                         175         while (--depth) {
179                 __fs64 *ptr;                      176                 __fs64 *ptr;
180                 struct buffer_head *bh;           177                 struct buffer_head *bh;
181                 unsigned n = *p++;                178                 unsigned n = *p++;
182                                                   179 
183                 bh = sb_bread(sb, uspi->s_sbba    180                 bh = sb_bread(sb, uspi->s_sbbase +
184                                   fs64_to_cpu(    181                                   fs64_to_cpu(sb, q->key64) + (n>>shift));
185                 if (!bh)                          182                 if (!bh)
186                         goto no_block;            183                         goto no_block;
187                 ptr = (__fs64 *)bh->b_data + (    184                 ptr = (__fs64 *)bh->b_data + (n & mask);
188                 if (!grow_chain64(ufsi, bh, pt    185                 if (!grow_chain64(ufsi, bh, ptr, chain, ++q))
189                         goto changed;             186                         goto changed;
190                 if (!q->key64)                    187                 if (!q->key64)
191                         goto no_block;            188                         goto no_block;
192         }                                         189         }
193         res = fs64_to_cpu(sb, q->key64);          190         res = fs64_to_cpu(sb, q->key64);
194 found:                                            191 found:
195         res += uspi->s_sbbase;                    192         res += uspi->s_sbbase;
196 no_block:                                         193 no_block:
197         while (q > chain) {                       194         while (q > chain) {
198                 brelse(q->bh);                    195                 brelse(q->bh);
199                 q--;                              196                 q--;
200         }                                         197         }
201         return res;                               198         return res;
202                                                   199 
203 changed:                                          200 changed:
204         while (q > chain) {                       201         while (q > chain) {
205                 brelse(q->bh);                    202                 brelse(q->bh);
206                 q--;                              203                 q--;
207         }                                         204         }
208         goto again;                               205         goto again;
209 }                                                 206 }
210                                                   207 
211 /*                                                208 /*
212  * Unpacking tails: we have a file with partia    209  * Unpacking tails: we have a file with partial final block and
213  * we had been asked to extend it.  If the fra    210  * we had been asked to extend it.  If the fragment being written
214  * is within the same block, we need to extend    211  * is within the same block, we need to extend the tail just to cover
215  * that fragment.  Otherwise the tail is exten    212  * that fragment.  Otherwise the tail is extended to full block.
216  *                                                213  *
217  * Note that we might need to create a _new_ t    214  * Note that we might need to create a _new_ tail, but that will
218  * be handled elsewhere; this is strictly for     215  * be handled elsewhere; this is strictly for resizing old
219  * ones.                                          216  * ones.
220  */                                               217  */
221 static bool                                       218 static bool
222 ufs_extend_tail(struct inode *inode, u64 write    219 ufs_extend_tail(struct inode *inode, u64 writes_to,
223                   int *err, struct page *locke    220                   int *err, struct page *locked_page)
224 {                                                 221 {
225         struct ufs_inode_info *ufsi = UFS_I(in    222         struct ufs_inode_info *ufsi = UFS_I(inode);
226         struct super_block *sb = inode->i_sb;     223         struct super_block *sb = inode->i_sb;
227         struct ufs_sb_private_info *uspi = UFS    224         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
228         unsigned lastfrag = ufsi->i_lastfrag;     225         unsigned lastfrag = ufsi->i_lastfrag;   /* it's a short file, so unsigned is enough */
229         unsigned block = ufs_fragstoblks(lastf    226         unsigned block = ufs_fragstoblks(lastfrag);
230         unsigned new_size;                        227         unsigned new_size;
231         void *p;                                  228         void *p;
232         u64 tmp;                                  229         u64 tmp;
233                                                   230 
234         if (writes_to < (lastfrag | uspi->s_fp    231         if (writes_to < (lastfrag | uspi->s_fpbmask))
235                 new_size = (writes_to & uspi->    232                 new_size = (writes_to & uspi->s_fpbmask) + 1;
236         else                                      233         else
237                 new_size = uspi->s_fpb;           234                 new_size = uspi->s_fpb;
238                                                   235 
239         p = ufs_get_direct_data_ptr(uspi, ufsi    236         p = ufs_get_direct_data_ptr(uspi, ufsi, block);
240         tmp = ufs_new_fragments(inode, p, last    237         tmp = ufs_new_fragments(inode, p, lastfrag, ufs_data_ptr_to_cpu(sb, p),
241                                 new_size - (la    238                                 new_size - (lastfrag & uspi->s_fpbmask), err,
242                                 locked_page);     239                                 locked_page);
243         return tmp != 0;                          240         return tmp != 0;
244 }                                                 241 }
245                                                   242 
246 /**                                               243 /**
247  * ufs_inode_getfrag() - allocate new fragment    244  * ufs_inode_getfrag() - allocate new fragment(s)
248  * @inode: pointer to inode                       245  * @inode: pointer to inode
249  * @index: number of block pointer within the     246  * @index: number of block pointer within the inode's array.
250  * @new_fragment: number of new allocated frag    247  * @new_fragment: number of new allocated fragment(s)
251  * @err: we set it if something wrong             248  * @err: we set it if something wrong
252  * @new: we set it if we allocate new block       249  * @new: we set it if we allocate new block
253  * @locked_page: for ufs_new_fragments()          250  * @locked_page: for ufs_new_fragments()
254  */                                               251  */
255 static u64                                        252 static u64
256 ufs_inode_getfrag(struct inode *inode, unsigne    253 ufs_inode_getfrag(struct inode *inode, unsigned index,
257                   sector_t new_fragment, int *    254                   sector_t new_fragment, int *err,
258                   int *new, struct page *locke    255                   int *new, struct page *locked_page)
259 {                                                 256 {
260         struct ufs_inode_info *ufsi = UFS_I(in    257         struct ufs_inode_info *ufsi = UFS_I(inode);
261         struct super_block *sb = inode->i_sb;     258         struct super_block *sb = inode->i_sb;
262         struct ufs_sb_private_info *uspi = UFS    259         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
263         u64 tmp, goal, lastfrag;                  260         u64 tmp, goal, lastfrag;
264         unsigned nfrags = uspi->s_fpb;            261         unsigned nfrags = uspi->s_fpb;
265         void *p;                                  262         void *p;
266                                                   263 
267         /* TODO : to be done for write support    264         /* TODO : to be done for write support
268         if ( (flags & UFS_TYPE_MASK) == UFS_TY    265         if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
269              goto ufs2;                           266              goto ufs2;
270          */                                       267          */
271                                                   268 
272         p = ufs_get_direct_data_ptr(uspi, ufsi    269         p = ufs_get_direct_data_ptr(uspi, ufsi, index);
273         tmp = ufs_data_ptr_to_cpu(sb, p);         270         tmp = ufs_data_ptr_to_cpu(sb, p);
274         if (tmp)                                  271         if (tmp)
275                 goto out;                         272                 goto out;
276                                                   273 
277         lastfrag = ufsi->i_lastfrag;              274         lastfrag = ufsi->i_lastfrag;
278                                                   275 
279         /* will that be a new tail? */            276         /* will that be a new tail? */
280         if (new_fragment < UFS_NDIR_FRAGMENT &    277         if (new_fragment < UFS_NDIR_FRAGMENT && new_fragment >= lastfrag)
281                 nfrags = (new_fragment & uspi-    278                 nfrags = (new_fragment & uspi->s_fpbmask) + 1;
282                                                   279 
283         goal = 0;                                 280         goal = 0;
284         if (index) {                              281         if (index) {
285                 goal = ufs_data_ptr_to_cpu(sb,    282                 goal = ufs_data_ptr_to_cpu(sb,
286                                  ufs_get_direc    283                                  ufs_get_direct_data_ptr(uspi, ufsi, index - 1));
287                 if (goal)                         284                 if (goal)
288                         goal += uspi->s_fpb;      285                         goal += uspi->s_fpb;
289         }                                         286         }
290         tmp = ufs_new_fragments(inode, p, ufs_    287         tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment),
291                                 goal, nfrags,     288                                 goal, nfrags, err, locked_page);
292                                                   289 
293         if (!tmp) {                               290         if (!tmp) {
294                 *err = -ENOSPC;                   291                 *err = -ENOSPC;
295                 return 0;                         292                 return 0;
296         }                                         293         }
297                                                   294 
298         if (new)                                  295         if (new)
299                 *new = 1;                         296                 *new = 1;
300         inode_set_ctime_current(inode);        !! 297         inode->i_ctime = current_time(inode);
301         if (IS_SYNC(inode))                       298         if (IS_SYNC(inode))
302                 ufs_sync_inode (inode);           299                 ufs_sync_inode (inode);
303         mark_inode_dirty(inode);                  300         mark_inode_dirty(inode);
304 out:                                              301 out:
305         return tmp + uspi->s_sbbase;              302         return tmp + uspi->s_sbbase;
306                                                   303 
307      /* This part : To be implemented ....        304      /* This part : To be implemented ....
308         Required only for writing, not require    305         Required only for writing, not required for READ-ONLY.
309 ufs2:                                             306 ufs2:
310                                                   307 
311         u2_block = ufs_fragstoblks(fragment);     308         u2_block = ufs_fragstoblks(fragment);
312         u2_blockoff = ufs_fragnum(fragment);      309         u2_blockoff = ufs_fragnum(fragment);
313         p = ufsi->i_u1.u2_i_data + block;         310         p = ufsi->i_u1.u2_i_data + block;
314         goal = 0;                                 311         goal = 0;
315                                                   312 
316 repeat2:                                          313 repeat2:
317         tmp = fs32_to_cpu(sb, *p);                314         tmp = fs32_to_cpu(sb, *p);
318         lastfrag = ufsi->i_lastfrag;              315         lastfrag = ufsi->i_lastfrag;
319                                                   316 
320      */                                           317      */
321 }                                                 318 }
322                                                   319 
323 /**                                               320 /**
324  * ufs_inode_getblock() - allocate new block      321  * ufs_inode_getblock() - allocate new block
325  * @inode: pointer to inode                       322  * @inode: pointer to inode
326  * @ind_block: block number of the indirect bl    323  * @ind_block: block number of the indirect block
327  * @index: number of pointer within the indire    324  * @index: number of pointer within the indirect block
328  * @new_fragment: number of new allocated frag    325  * @new_fragment: number of new allocated fragment
329  *  (block will hold this fragment and also us    326  *  (block will hold this fragment and also uspi->s_fpb-1)
330  * @err: see ufs_inode_getfrag()                  327  * @err: see ufs_inode_getfrag()
331  * @new: see ufs_inode_getfrag()                  328  * @new: see ufs_inode_getfrag()
332  * @locked_page: see ufs_inode_getfrag()          329  * @locked_page: see ufs_inode_getfrag()
333  */                                               330  */
334 static u64                                        331 static u64
335 ufs_inode_getblock(struct inode *inode, u64 in    332 ufs_inode_getblock(struct inode *inode, u64 ind_block,
336                   unsigned index, sector_t new    333                   unsigned index, sector_t new_fragment, int *err,
337                   int *new, struct page *locke    334                   int *new, struct page *locked_page)
338 {                                                 335 {
339         struct super_block *sb = inode->i_sb;     336         struct super_block *sb = inode->i_sb;
340         struct ufs_sb_private_info *uspi = UFS    337         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
341         int shift = uspi->s_apbshift - uspi->s    338         int shift = uspi->s_apbshift - uspi->s_fpbshift;
342         u64 tmp = 0, goal;                        339         u64 tmp = 0, goal;
343         struct buffer_head *bh;                   340         struct buffer_head *bh;
344         void *p;                                  341         void *p;
345                                                   342 
346         if (!ind_block)                           343         if (!ind_block)
347                 return 0;                         344                 return 0;
348                                                   345 
349         bh = sb_bread(sb, ind_block + (index >    346         bh = sb_bread(sb, ind_block + (index >> shift));
350         if (unlikely(!bh)) {                      347         if (unlikely(!bh)) {
351                 *err = -EIO;                      348                 *err = -EIO;
352                 return 0;                         349                 return 0;
353         }                                         350         }
354                                                   351 
355         index &= uspi->s_apbmask >> uspi->s_fp    352         index &= uspi->s_apbmask >> uspi->s_fpbshift;
356         if (uspi->fs_magic == UFS2_MAGIC)         353         if (uspi->fs_magic == UFS2_MAGIC)
357                 p = (__fs64 *)bh->b_data + ind    354                 p = (__fs64 *)bh->b_data + index;
358         else                                      355         else
359                 p = (__fs32 *)bh->b_data + ind    356                 p = (__fs32 *)bh->b_data + index;
360                                                   357 
361         tmp = ufs_data_ptr_to_cpu(sb, p);         358         tmp = ufs_data_ptr_to_cpu(sb, p);
362         if (tmp)                                  359         if (tmp)
363                 goto out;                         360                 goto out;
364                                                   361 
365         if (index && (uspi->fs_magic == UFS2_M    362         if (index && (uspi->fs_magic == UFS2_MAGIC ?
366                       (tmp = fs64_to_cpu(sb, (    363                       (tmp = fs64_to_cpu(sb, ((__fs64 *)bh->b_data)[index-1])) :
367                       (tmp = fs32_to_cpu(sb, (    364                       (tmp = fs32_to_cpu(sb, ((__fs32 *)bh->b_data)[index-1]))))
368                 goal = tmp + uspi->s_fpb;         365                 goal = tmp + uspi->s_fpb;
369         else                                      366         else
370                 goal = bh->b_blocknr + uspi->s    367                 goal = bh->b_blocknr + uspi->s_fpb;
371         tmp = ufs_new_fragments(inode, p, ufs_    368         tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
372                                 uspi->s_fpb, e    369                                 uspi->s_fpb, err, locked_page);
373         if (!tmp)                                 370         if (!tmp)
374                 goto out;                         371                 goto out;
375                                                   372 
376         if (new)                                  373         if (new)
377                 *new = 1;                         374                 *new = 1;
378                                                   375 
379         mark_buffer_dirty(bh);                    376         mark_buffer_dirty(bh);
380         if (IS_SYNC(inode))                       377         if (IS_SYNC(inode))
381                 sync_dirty_buffer(bh);            378                 sync_dirty_buffer(bh);
382         inode_set_ctime_current(inode);        !! 379         inode->i_ctime = current_time(inode);
383         mark_inode_dirty(inode);                  380         mark_inode_dirty(inode);
384 out:                                              381 out:
385         brelse (bh);                              382         brelse (bh);
386         UFSD("EXIT\n");                           383         UFSD("EXIT\n");
387         if (tmp)                                  384         if (tmp)
388                 tmp += uspi->s_sbbase;            385                 tmp += uspi->s_sbbase;
389         return tmp;                               386         return tmp;
390 }                                                 387 }
391                                                   388 
392 /**                                               389 /**
393  * ufs_getfrag_block() - `get_block_t' functio    390  * ufs_getfrag_block() - `get_block_t' function, interface between UFS and
394  * read_folio, writepages and so on            !! 391  * readpage, writepage and so on
395  */                                               392  */
396                                                   393 
397 static int ufs_getfrag_block(struct inode *ino    394 static int ufs_getfrag_block(struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create)
398 {                                                 395 {
399         struct super_block *sb = inode->i_sb;     396         struct super_block *sb = inode->i_sb;
400         struct ufs_sb_private_info *uspi = UFS    397         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
401         int err = 0, new = 0;                     398         int err = 0, new = 0;
402         unsigned offsets[4];                      399         unsigned offsets[4];
403         int depth = ufs_block_to_path(inode, f    400         int depth = ufs_block_to_path(inode, fragment >> uspi->s_fpbshift, offsets);
404         u64 phys64 = 0;                           401         u64 phys64 = 0;
405         unsigned frag = fragment & uspi->s_fpb    402         unsigned frag = fragment & uspi->s_fpbmask;
406                                                   403 
407         phys64 = ufs_frag_map(inode, offsets,  !! 404         if (!create) {
408         if (!create)                           !! 405                 phys64 = ufs_frag_map(inode, offsets, depth);
409                 goto done;                     !! 406                 if (phys64)
410                                                !! 407                         map_bh(bh_result, sb, phys64 + frag);
411         if (phys64) {                          !! 408                 return 0;
412                 if (fragment >= UFS_NDIR_FRAGM << 
413                         goto done;             << 
414                 read_seqlock_excl(&UFS_I(inode << 
415                 if (fragment < UFS_I(inode)->i << 
416                         read_sequnlock_excl(&U << 
417                         goto done;             << 
418                 }                              << 
419                 read_sequnlock_excl(&UFS_I(ino << 
420         }                                         409         }
                                                   >> 410 
421         /* This code entered only while writin    411         /* This code entered only while writing ....? */
422                                                   412 
423         mutex_lock(&UFS_I(inode)->truncate_mut    413         mutex_lock(&UFS_I(inode)->truncate_mutex);
424                                                   414 
425         UFSD("ENTER, ino %lu, fragment %llu\n"    415         UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
426         if (unlikely(!depth)) {                   416         if (unlikely(!depth)) {
427                 ufs_warning(sb, "ufs_get_block    417                 ufs_warning(sb, "ufs_get_block", "block > big");
428                 err = -EIO;                       418                 err = -EIO;
429                 goto out;                         419                 goto out;
430         }                                         420         }
431                                                   421 
432         if (UFS_I(inode)->i_lastfrag < UFS_NDI    422         if (UFS_I(inode)->i_lastfrag < UFS_NDIR_FRAGMENT) {
433                 unsigned lastfrag = UFS_I(inod    423                 unsigned lastfrag = UFS_I(inode)->i_lastfrag;
434                 unsigned tailfrags = lastfrag     424                 unsigned tailfrags = lastfrag & uspi->s_fpbmask;
435                 if (tailfrags && fragment >= l    425                 if (tailfrags && fragment >= lastfrag) {
436                         if (!ufs_extend_tail(i    426                         if (!ufs_extend_tail(inode, fragment,
437                                              &    427                                              &err, bh_result->b_page))
438                                 goto out;         428                                 goto out;
439                 }                                 429                 }
440         }                                         430         }
441                                                   431 
442         if (depth == 1) {                         432         if (depth == 1) {
443                 phys64 = ufs_inode_getfrag(ino    433                 phys64 = ufs_inode_getfrag(inode, offsets[0], fragment,
444                                            &er    434                                            &err, &new, bh_result->b_page);
445         } else {                                  435         } else {
446                 int i;                            436                 int i;
447                 phys64 = ufs_inode_getfrag(ino    437                 phys64 = ufs_inode_getfrag(inode, offsets[0], fragment,
448                                            &er    438                                            &err, NULL, NULL);
449                 for (i = 1; i < depth - 1; i++    439                 for (i = 1; i < depth - 1; i++)
450                         phys64 = ufs_inode_get    440                         phys64 = ufs_inode_getblock(inode, phys64, offsets[i],
451                                                   441                                                 fragment, &err, NULL, NULL);
452                 phys64 = ufs_inode_getblock(in    442                 phys64 = ufs_inode_getblock(inode, phys64, offsets[depth - 1],
453                                         fragme    443                                         fragment, &err, &new, bh_result->b_page);
454         }                                         444         }
455 out:                                              445 out:
456         if (phys64) {                             446         if (phys64) {
457                 phys64 += frag;                   447                 phys64 += frag;
458                 map_bh(bh_result, sb, phys64);    448                 map_bh(bh_result, sb, phys64);
459                 if (new)                          449                 if (new)
460                         set_buffer_new(bh_resu    450                         set_buffer_new(bh_result);
461         }                                         451         }
462         mutex_unlock(&UFS_I(inode)->truncate_m    452         mutex_unlock(&UFS_I(inode)->truncate_mutex);
463         return err;                               453         return err;
464                                                << 
465 done:                                          << 
466         if (phys64)                            << 
467                 map_bh(bh_result, sb, phys64 + << 
468         return 0;                              << 
469 }                                                 454 }
470                                                   455 
471 static int ufs_writepages(struct address_space !! 456 static int ufs_writepage(struct page *page, struct writeback_control *wbc)
472                 struct writeback_control *wbc) << 
473 {                                                 457 {
474         return mpage_writepages(mapping, wbc,  !! 458         return block_write_full_page(page,ufs_getfrag_block,wbc);
475 }                                                 459 }
476                                                   460 
477 static int ufs_read_folio(struct file *file, s !! 461 static int ufs_readpage(struct file *file, struct page *page)
478 {                                                 462 {
479         return block_read_full_folio(folio, uf !! 463         return block_read_full_page(page,ufs_getfrag_block);
480 }                                                 464 }
481                                                   465 
482 int ufs_prepare_chunk(struct page *page, loff_    466 int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len)
483 {                                                 467 {
484         return __block_write_begin(page, pos,     468         return __block_write_begin(page, pos, len, ufs_getfrag_block);
485 }                                                 469 }
486                                                   470 
487 static void ufs_truncate_blocks(struct inode *    471 static void ufs_truncate_blocks(struct inode *);
488                                                   472 
489 static void ufs_write_failed(struct address_sp    473 static void ufs_write_failed(struct address_space *mapping, loff_t to)
490 {                                                 474 {
491         struct inode *inode = mapping->host;      475         struct inode *inode = mapping->host;
492                                                   476 
493         if (to > inode->i_size) {                 477         if (to > inode->i_size) {
494                 truncate_pagecache(inode, inod    478                 truncate_pagecache(inode, inode->i_size);
495                 ufs_truncate_blocks(inode);       479                 ufs_truncate_blocks(inode);
496         }                                         480         }
497 }                                                 481 }
498                                                   482 
499 static int ufs_write_begin(struct file *file,     483 static int ufs_write_begin(struct file *file, struct address_space *mapping,
500                         loff_t pos, unsigned l !! 484                         loff_t pos, unsigned len, unsigned flags,
501                         struct page **pagep, v    485                         struct page **pagep, void **fsdata)
502 {                                                 486 {
503         int ret;                                  487         int ret;
504                                                   488 
505         ret = block_write_begin(mapping, pos,  !! 489         ret = block_write_begin(mapping, pos, len, flags, pagep,
                                                   >> 490                                 ufs_getfrag_block);
506         if (unlikely(ret))                        491         if (unlikely(ret))
507                 ufs_write_failed(mapping, pos     492                 ufs_write_failed(mapping, pos + len);
508                                                   493 
509         return ret;                               494         return ret;
510 }                                                 495 }
511                                                   496 
512 static int ufs_write_end(struct file *file, st    497 static int ufs_write_end(struct file *file, struct address_space *mapping,
513                         loff_t pos, unsigned l    498                         loff_t pos, unsigned len, unsigned copied,
514                         struct page *page, voi    499                         struct page *page, void *fsdata)
515 {                                                 500 {
516         int ret;                                  501         int ret;
517                                                   502 
518         ret = generic_write_end(file, mapping,    503         ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
519         if (ret < len)                            504         if (ret < len)
520                 ufs_write_failed(mapping, pos     505                 ufs_write_failed(mapping, pos + len);
521         return ret;                               506         return ret;
522 }                                                 507 }
523                                                   508 
524 static sector_t ufs_bmap(struct address_space     509 static sector_t ufs_bmap(struct address_space *mapping, sector_t block)
525 {                                                 510 {
526         return generic_block_bmap(mapping,bloc    511         return generic_block_bmap(mapping,block,ufs_getfrag_block);
527 }                                                 512 }
528                                                   513 
529 const struct address_space_operations ufs_aops    514 const struct address_space_operations ufs_aops = {
530         .dirty_folio = block_dirty_folio,      !! 515         .readpage = ufs_readpage,
531         .invalidate_folio = block_invalidate_f !! 516         .writepage = ufs_writepage,
532         .read_folio = ufs_read_folio,          << 
533         .writepages = ufs_writepages,          << 
534         .write_begin = ufs_write_begin,           517         .write_begin = ufs_write_begin,
535         .write_end = ufs_write_end,               518         .write_end = ufs_write_end,
536         .migrate_folio = buffer_migrate_folio, << 
537         .bmap = ufs_bmap                          519         .bmap = ufs_bmap
538 };                                                520 };
539                                                   521 
540 static void ufs_set_inode_ops(struct inode *in    522 static void ufs_set_inode_ops(struct inode *inode)
541 {                                                 523 {
542         if (S_ISREG(inode->i_mode)) {             524         if (S_ISREG(inode->i_mode)) {
543                 inode->i_op = &ufs_file_inode_    525                 inode->i_op = &ufs_file_inode_operations;
544                 inode->i_fop = &ufs_file_opera    526                 inode->i_fop = &ufs_file_operations;
545                 inode->i_mapping->a_ops = &ufs    527                 inode->i_mapping->a_ops = &ufs_aops;
546         } else if (S_ISDIR(inode->i_mode)) {      528         } else if (S_ISDIR(inode->i_mode)) {
547                 inode->i_op = &ufs_dir_inode_o    529                 inode->i_op = &ufs_dir_inode_operations;
548                 inode->i_fop = &ufs_dir_operat    530                 inode->i_fop = &ufs_dir_operations;
549                 inode->i_mapping->a_ops = &ufs    531                 inode->i_mapping->a_ops = &ufs_aops;
550         } else if (S_ISLNK(inode->i_mode)) {      532         } else if (S_ISLNK(inode->i_mode)) {
551                 if (!inode->i_blocks) {           533                 if (!inode->i_blocks) {
552                         inode->i_link = (char     534                         inode->i_link = (char *)UFS_I(inode)->i_u1.i_symlink;
553                         inode->i_op = &simple_    535                         inode->i_op = &simple_symlink_inode_operations;
554                 } else {                          536                 } else {
555                         inode->i_mapping->a_op    537                         inode->i_mapping->a_ops = &ufs_aops;
556                         inode->i_op = &page_sy    538                         inode->i_op = &page_symlink_inode_operations;
557                         inode_nohighmem(inode)    539                         inode_nohighmem(inode);
558                 }                                 540                 }
559         } else                                    541         } else
560                 init_special_inode(inode, inod    542                 init_special_inode(inode, inode->i_mode,
561                                    ufs_get_ino    543                                    ufs_get_inode_dev(inode->i_sb, UFS_I(inode)));
562 }                                                 544 }
563                                                   545 
564 static int ufs1_read_inode(struct inode *inode    546 static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode)
565 {                                                 547 {
566         struct ufs_inode_info *ufsi = UFS_I(in    548         struct ufs_inode_info *ufsi = UFS_I(inode);
567         struct super_block *sb = inode->i_sb;     549         struct super_block *sb = inode->i_sb;
568         umode_t mode;                             550         umode_t mode;
569                                                   551 
570         /*                                        552         /*
571          * Copy data to the in-core inode.        553          * Copy data to the in-core inode.
572          */                                       554          */
573         inode->i_mode = mode = fs16_to_cpu(sb,    555         inode->i_mode = mode = fs16_to_cpu(sb, ufs_inode->ui_mode);
574         set_nlink(inode, fs16_to_cpu(sb, ufs_i    556         set_nlink(inode, fs16_to_cpu(sb, ufs_inode->ui_nlink));
575         if (inode->i_nlink == 0)               !! 557         if (inode->i_nlink == 0) {
576                 return -ESTALE;                !! 558                 ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
                                                   >> 559                 return -1;
                                                   >> 560         }
577                                                   561 
578         /*                                        562         /*
579          * Linux now has 32-bit uid and gid, s    563          * Linux now has 32-bit uid and gid, so we can support EFT.
580          */                                       564          */
581         i_uid_write(inode, ufs_get_inode_uid(s    565         i_uid_write(inode, ufs_get_inode_uid(sb, ufs_inode));
582         i_gid_write(inode, ufs_get_inode_gid(s    566         i_gid_write(inode, ufs_get_inode_gid(sb, ufs_inode));
583                                                   567 
584         inode->i_size = fs64_to_cpu(sb, ufs_in    568         inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size);
585         inode_set_atime(inode,                 !! 569         inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec);
586                         (signed)fs32_to_cpu(sb !! 570         inode->i_ctime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_ctime.tv_sec);
587                         0);                    !! 571         inode->i_mtime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_mtime.tv_sec);
588         inode_set_ctime(inode,                 !! 572         inode->i_mtime.tv_nsec = 0;
589                         (signed)fs32_to_cpu(sb !! 573         inode->i_atime.tv_nsec = 0;
590                         0);                    !! 574         inode->i_ctime.tv_nsec = 0;
591         inode_set_mtime(inode,                 << 
592                         (signed)fs32_to_cpu(sb << 
593                         0);                    << 
594         inode->i_blocks = fs32_to_cpu(sb, ufs_    575         inode->i_blocks = fs32_to_cpu(sb, ufs_inode->ui_blocks);
595         inode->i_generation = fs32_to_cpu(sb,     576         inode->i_generation = fs32_to_cpu(sb, ufs_inode->ui_gen);
596         ufsi->i_flags = fs32_to_cpu(sb, ufs_in    577         ufsi->i_flags = fs32_to_cpu(sb, ufs_inode->ui_flags);
597         ufsi->i_shadow = fs32_to_cpu(sb, ufs_i    578         ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
598         ufsi->i_oeftflag = fs32_to_cpu(sb, ufs    579         ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
599                                                   580 
600                                                   581 
601         if (S_ISCHR(mode) || S_ISBLK(mode) ||     582         if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
602                 memcpy(ufsi->i_u1.i_data, &ufs    583                 memcpy(ufsi->i_u1.i_data, &ufs_inode->ui_u2.ui_addr,
603                        sizeof(ufs_inode->ui_u2    584                        sizeof(ufs_inode->ui_u2.ui_addr));
604         } else {                                  585         } else {
605                 memcpy(ufsi->i_u1.i_symlink, u    586                 memcpy(ufsi->i_u1.i_symlink, ufs_inode->ui_u2.ui_symlink,
606                        sizeof(ufs_inode->ui_u2    587                        sizeof(ufs_inode->ui_u2.ui_symlink) - 1);
607                 ufsi->i_u1.i_symlink[sizeof(uf    588                 ufsi->i_u1.i_symlink[sizeof(ufs_inode->ui_u2.ui_symlink) - 1] = 0;
608         }                                         589         }
609         return 0;                                 590         return 0;
610 }                                                 591 }
611                                                   592 
612 static int ufs2_read_inode(struct inode *inode    593 static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
613 {                                                 594 {
614         struct ufs_inode_info *ufsi = UFS_I(in    595         struct ufs_inode_info *ufsi = UFS_I(inode);
615         struct super_block *sb = inode->i_sb;     596         struct super_block *sb = inode->i_sb;
616         umode_t mode;                             597         umode_t mode;
617                                                   598 
618         UFSD("Reading ufs2 inode, ino %lu\n",     599         UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
619         /*                                        600         /*
620          * Copy data to the in-core inode.        601          * Copy data to the in-core inode.
621          */                                       602          */
622         inode->i_mode = mode = fs16_to_cpu(sb,    603         inode->i_mode = mode = fs16_to_cpu(sb, ufs2_inode->ui_mode);
623         set_nlink(inode, fs16_to_cpu(sb, ufs2_    604         set_nlink(inode, fs16_to_cpu(sb, ufs2_inode->ui_nlink));
624         if (inode->i_nlink == 0)               !! 605         if (inode->i_nlink == 0) {
625                 return -ESTALE;                !! 606                 ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
                                                   >> 607                 return -1;
                                                   >> 608         }
626                                                   609 
627         /*                                        610         /*
628          * Linux now has 32-bit uid and gid, s    611          * Linux now has 32-bit uid and gid, so we can support EFT.
629          */                                       612          */
630         i_uid_write(inode, fs32_to_cpu(sb, ufs    613         i_uid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_uid));
631         i_gid_write(inode, fs32_to_cpu(sb, ufs    614         i_gid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_gid));
632                                                   615 
633         inode->i_size = fs64_to_cpu(sb, ufs2_i    616         inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size);
634         inode_set_atime(inode, fs64_to_cpu(sb, !! 617         inode->i_atime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_atime);
635                         fs32_to_cpu(sb, ufs2_i !! 618         inode->i_ctime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_ctime);
636         inode_set_ctime(inode, fs64_to_cpu(sb, !! 619         inode->i_mtime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_mtime);
637                         fs32_to_cpu(sb, ufs2_i !! 620         inode->i_atime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_atimensec);
638         inode_set_mtime(inode, fs64_to_cpu(sb, !! 621         inode->i_ctime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_ctimensec);
639                         fs32_to_cpu(sb, ufs2_i !! 622         inode->i_mtime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_mtimensec);
640         inode->i_blocks = fs64_to_cpu(sb, ufs2    623         inode->i_blocks = fs64_to_cpu(sb, ufs2_inode->ui_blocks);
641         inode->i_generation = fs32_to_cpu(sb,     624         inode->i_generation = fs32_to_cpu(sb, ufs2_inode->ui_gen);
642         ufsi->i_flags = fs32_to_cpu(sb, ufs2_i    625         ufsi->i_flags = fs32_to_cpu(sb, ufs2_inode->ui_flags);
643         /*                                        626         /*
644         ufsi->i_shadow = fs32_to_cpu(sb, ufs_i    627         ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
645         ufsi->i_oeftflag = fs32_to_cpu(sb, ufs    628         ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
646         */                                        629         */
647                                                   630 
648         if (S_ISCHR(mode) || S_ISBLK(mode) ||     631         if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
649                 memcpy(ufsi->i_u1.u2_i_data, &    632                 memcpy(ufsi->i_u1.u2_i_data, &ufs2_inode->ui_u2.ui_addr,
650                        sizeof(ufs2_inode->ui_u    633                        sizeof(ufs2_inode->ui_u2.ui_addr));
651         } else {                                  634         } else {
652                 memcpy(ufsi->i_u1.i_symlink, u    635                 memcpy(ufsi->i_u1.i_symlink, ufs2_inode->ui_u2.ui_symlink,
653                        sizeof(ufs2_inode->ui_u    636                        sizeof(ufs2_inode->ui_u2.ui_symlink) - 1);
654                 ufsi->i_u1.i_symlink[sizeof(uf    637                 ufsi->i_u1.i_symlink[sizeof(ufs2_inode->ui_u2.ui_symlink) - 1] = 0;
655         }                                         638         }
656         return 0;                                 639         return 0;
657 }                                                 640 }
658                                                   641 
659 struct inode *ufs_iget(struct super_block *sb,    642 struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
660 {                                                 643 {
661         struct ufs_inode_info *ufsi;              644         struct ufs_inode_info *ufsi;
662         struct ufs_sb_private_info *uspi = UFS    645         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
663         struct buffer_head * bh;                  646         struct buffer_head * bh;
664         struct inode *inode;                      647         struct inode *inode;
665         int err = -EIO;                        !! 648         int err;
666                                                   649 
667         UFSD("ENTER, ino %lu\n", ino);            650         UFSD("ENTER, ino %lu\n", ino);
668                                                   651 
669         if (ino < UFS_ROOTINO || ino > (uspi->    652         if (ino < UFS_ROOTINO || ino > (uspi->s_ncg * uspi->s_ipg)) {
670                 ufs_warning(sb, "ufs_read_inod    653                 ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n",
671                             ino);                 654                             ino);
672                 return ERR_PTR(-EIO);             655                 return ERR_PTR(-EIO);
673         }                                         656         }
674                                                   657 
675         inode = iget_locked(sb, ino);             658         inode = iget_locked(sb, ino);
676         if (!inode)                               659         if (!inode)
677                 return ERR_PTR(-ENOMEM);          660                 return ERR_PTR(-ENOMEM);
678         if (!(inode->i_state & I_NEW))            661         if (!(inode->i_state & I_NEW))
679                 return inode;                     662                 return inode;
680                                                   663 
681         ufsi = UFS_I(inode);                      664         ufsi = UFS_I(inode);
682                                                   665 
683         bh = sb_bread(sb, uspi->s_sbbase + ufs    666         bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
684         if (!bh) {                                667         if (!bh) {
685                 ufs_warning(sb, "ufs_read_inod    668                 ufs_warning(sb, "ufs_read_inode", "unable to read inode %lu\n",
686                             inode->i_ino);        669                             inode->i_ino);
687                 goto bad_inode;                   670                 goto bad_inode;
688         }                                         671         }
689         if ((UFS_SB(sb)->s_flags & UFS_TYPE_MA    672         if ((UFS_SB(sb)->s_flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
690                 struct ufs2_inode *ufs2_inode     673                 struct ufs2_inode *ufs2_inode = (struct ufs2_inode *)bh->b_data;
691                                                   674 
692                 err = ufs2_read_inode(inode,      675                 err = ufs2_read_inode(inode,
693                                       ufs2_ino    676                                       ufs2_inode + ufs_inotofsbo(inode->i_ino));
694         } else {                                  677         } else {
695                 struct ufs_inode *ufs_inode =     678                 struct ufs_inode *ufs_inode = (struct ufs_inode *)bh->b_data;
696                                                   679 
697                 err = ufs1_read_inode(inode,      680                 err = ufs1_read_inode(inode,
698                                       ufs_inod    681                                       ufs_inode + ufs_inotofsbo(inode->i_ino));
699         }                                         682         }
700         brelse(bh);                            !! 683 
701         if (err)                                  684         if (err)
702                 goto bad_inode;                   685                 goto bad_inode;
703                                                !! 686         inode->i_version++;
704         inode_inc_iversion(inode);             << 
705         ufsi->i_lastfrag =                        687         ufsi->i_lastfrag =
706                 (inode->i_size + uspi->s_fsize    688                 (inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
707         ufsi->i_dir_start_lookup = 0;             689         ufsi->i_dir_start_lookup = 0;
708         ufsi->i_osync = 0;                        690         ufsi->i_osync = 0;
709                                                   691 
710         ufs_set_inode_ops(inode);                 692         ufs_set_inode_ops(inode);
711                                                   693 
                                                   >> 694         brelse(bh);
                                                   >> 695 
712         UFSD("EXIT\n");                           696         UFSD("EXIT\n");
713         unlock_new_inode(inode);                  697         unlock_new_inode(inode);
714         return inode;                             698         return inode;
715                                                   699 
716 bad_inode:                                        700 bad_inode:
717         iget_failed(inode);                       701         iget_failed(inode);
718         return ERR_PTR(err);                   !! 702         return ERR_PTR(-EIO);
719 }                                                 703 }
720                                                   704 
721 static void ufs1_update_inode(struct inode *in    705 static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
722 {                                                 706 {
723         struct super_block *sb = inode->i_sb;     707         struct super_block *sb = inode->i_sb;
724         struct ufs_inode_info *ufsi = UFS_I(in    708         struct ufs_inode_info *ufsi = UFS_I(inode);
725                                                   709 
726         ufs_inode->ui_mode = cpu_to_fs16(sb, i    710         ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
727         ufs_inode->ui_nlink = cpu_to_fs16(sb,     711         ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
728                                                   712 
729         ufs_set_inode_uid(sb, ufs_inode, i_uid    713         ufs_set_inode_uid(sb, ufs_inode, i_uid_read(inode));
730         ufs_set_inode_gid(sb, ufs_inode, i_gid    714         ufs_set_inode_gid(sb, ufs_inode, i_gid_read(inode));
731                                                   715 
732         ufs_inode->ui_size = cpu_to_fs64(sb, i    716         ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
733         ufs_inode->ui_atime.tv_sec = cpu_to_fs !! 717         ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb, inode->i_atime.tv_sec);
734                                                << 
735         ufs_inode->ui_atime.tv_usec = 0;          718         ufs_inode->ui_atime.tv_usec = 0;
736         ufs_inode->ui_ctime.tv_sec = cpu_to_fs !! 719         ufs_inode->ui_ctime.tv_sec = cpu_to_fs32(sb, inode->i_ctime.tv_sec);
737                                                << 
738         ufs_inode->ui_ctime.tv_usec = 0;          720         ufs_inode->ui_ctime.tv_usec = 0;
739         ufs_inode->ui_mtime.tv_sec = cpu_to_fs !! 721         ufs_inode->ui_mtime.tv_sec = cpu_to_fs32(sb, inode->i_mtime.tv_sec);
740                                                << 
741         ufs_inode->ui_mtime.tv_usec = 0;          722         ufs_inode->ui_mtime.tv_usec = 0;
742         ufs_inode->ui_blocks = cpu_to_fs32(sb,    723         ufs_inode->ui_blocks = cpu_to_fs32(sb, inode->i_blocks);
743         ufs_inode->ui_flags = cpu_to_fs32(sb,     724         ufs_inode->ui_flags = cpu_to_fs32(sb, ufsi->i_flags);
744         ufs_inode->ui_gen = cpu_to_fs32(sb, in    725         ufs_inode->ui_gen = cpu_to_fs32(sb, inode->i_generation);
745                                                   726 
746         if ((UFS_SB(sb)->s_flags & UFS_UID_MAS    727         if ((UFS_SB(sb)->s_flags & UFS_UID_MASK) == UFS_UID_EFT) {
747                 ufs_inode->ui_u3.ui_sun.ui_sha    728                 ufs_inode->ui_u3.ui_sun.ui_shadow = cpu_to_fs32(sb, ufsi->i_shadow);
748                 ufs_inode->ui_u3.ui_sun.ui_oef    729                 ufs_inode->ui_u3.ui_sun.ui_oeftflag = cpu_to_fs32(sb, ufsi->i_oeftflag);
749         }                                         730         }
750                                                   731 
751         if (S_ISCHR(inode->i_mode) || S_ISBLK(    732         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
752                 /* ufs_inode->ui_u2.ui_addr.ui    733                 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
753                 ufs_inode->ui_u2.ui_addr.ui_db    734                 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.i_data[0];
754         } else if (inode->i_blocks) {             735         } else if (inode->i_blocks) {
755                 memcpy(&ufs_inode->ui_u2.ui_ad    736                 memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.i_data,
756                        sizeof(ufs_inode->ui_u2    737                        sizeof(ufs_inode->ui_u2.ui_addr));
757         }                                         738         }
758         else {                                    739         else {
759                 memcpy(&ufs_inode->ui_u2.ui_sy    740                 memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
760                        sizeof(ufs_inode->ui_u2    741                        sizeof(ufs_inode->ui_u2.ui_symlink));
761         }                                         742         }
762                                                   743 
763         if (!inode->i_nlink)                      744         if (!inode->i_nlink)
764                 memset (ufs_inode, 0, sizeof(s    745                 memset (ufs_inode, 0, sizeof(struct ufs_inode));
765 }                                                 746 }
766                                                   747 
767 static void ufs2_update_inode(struct inode *in    748 static void ufs2_update_inode(struct inode *inode, struct ufs2_inode *ufs_inode)
768 {                                                 749 {
769         struct super_block *sb = inode->i_sb;     750         struct super_block *sb = inode->i_sb;
770         struct ufs_inode_info *ufsi = UFS_I(in    751         struct ufs_inode_info *ufsi = UFS_I(inode);
771                                                   752 
772         UFSD("ENTER\n");                          753         UFSD("ENTER\n");
773         ufs_inode->ui_mode = cpu_to_fs16(sb, i    754         ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
774         ufs_inode->ui_nlink = cpu_to_fs16(sb,     755         ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
775                                                   756 
776         ufs_inode->ui_uid = cpu_to_fs32(sb, i_    757         ufs_inode->ui_uid = cpu_to_fs32(sb, i_uid_read(inode));
777         ufs_inode->ui_gid = cpu_to_fs32(sb, i_    758         ufs_inode->ui_gid = cpu_to_fs32(sb, i_gid_read(inode));
778                                                   759 
779         ufs_inode->ui_size = cpu_to_fs64(sb, i    760         ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
780         ufs_inode->ui_atime = cpu_to_fs64(sb,  !! 761         ufs_inode->ui_atime = cpu_to_fs64(sb, inode->i_atime.tv_sec);
781         ufs_inode->ui_atimensec = cpu_to_fs32( !! 762         ufs_inode->ui_atimensec = cpu_to_fs32(sb, inode->i_atime.tv_nsec);
782                                                !! 763         ufs_inode->ui_ctime = cpu_to_fs64(sb, inode->i_ctime.tv_sec);
783         ufs_inode->ui_ctime = cpu_to_fs64(sb,  !! 764         ufs_inode->ui_ctimensec = cpu_to_fs32(sb, inode->i_ctime.tv_nsec);
784         ufs_inode->ui_ctimensec = cpu_to_fs32( !! 765         ufs_inode->ui_mtime = cpu_to_fs64(sb, inode->i_mtime.tv_sec);
785                                                !! 766         ufs_inode->ui_mtimensec = cpu_to_fs32(sb, inode->i_mtime.tv_nsec);
786         ufs_inode->ui_mtime = cpu_to_fs64(sb,  << 
787         ufs_inode->ui_mtimensec = cpu_to_fs32( << 
788                                                << 
789                                                   767 
790         ufs_inode->ui_blocks = cpu_to_fs64(sb,    768         ufs_inode->ui_blocks = cpu_to_fs64(sb, inode->i_blocks);
791         ufs_inode->ui_flags = cpu_to_fs32(sb,     769         ufs_inode->ui_flags = cpu_to_fs32(sb, ufsi->i_flags);
792         ufs_inode->ui_gen = cpu_to_fs32(sb, in    770         ufs_inode->ui_gen = cpu_to_fs32(sb, inode->i_generation);
793                                                   771 
794         if (S_ISCHR(inode->i_mode) || S_ISBLK(    772         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
795                 /* ufs_inode->ui_u2.ui_addr.ui    773                 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
796                 ufs_inode->ui_u2.ui_addr.ui_db    774                 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.u2_i_data[0];
797         } else if (inode->i_blocks) {             775         } else if (inode->i_blocks) {
798                 memcpy(&ufs_inode->ui_u2.ui_ad    776                 memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.u2_i_data,
799                        sizeof(ufs_inode->ui_u2    777                        sizeof(ufs_inode->ui_u2.ui_addr));
800         } else {                                  778         } else {
801                 memcpy(&ufs_inode->ui_u2.ui_sy    779                 memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
802                        sizeof(ufs_inode->ui_u2    780                        sizeof(ufs_inode->ui_u2.ui_symlink));
803         }                                         781         }
804                                                   782 
805         if (!inode->i_nlink)                      783         if (!inode->i_nlink)
806                 memset (ufs_inode, 0, sizeof(s    784                 memset (ufs_inode, 0, sizeof(struct ufs2_inode));
807         UFSD("EXIT\n");                           785         UFSD("EXIT\n");
808 }                                                 786 }
809                                                   787 
810 static int ufs_update_inode(struct inode * ino    788 static int ufs_update_inode(struct inode * inode, int do_sync)
811 {                                                 789 {
812         struct super_block *sb = inode->i_sb;     790         struct super_block *sb = inode->i_sb;
813         struct ufs_sb_private_info *uspi = UFS    791         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
814         struct buffer_head * bh;                  792         struct buffer_head * bh;
815                                                   793 
816         UFSD("ENTER, ino %lu\n", inode->i_ino)    794         UFSD("ENTER, ino %lu\n", inode->i_ino);
817                                                   795 
818         if (inode->i_ino < UFS_ROOTINO ||         796         if (inode->i_ino < UFS_ROOTINO ||
819             inode->i_ino > (uspi->s_ncg * uspi    797             inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
820                 ufs_warning (sb, "ufs_read_ino    798                 ufs_warning (sb, "ufs_read_inode", "bad inode number (%lu)\n", inode->i_ino);
821                 return -1;                        799                 return -1;
822         }                                         800         }
823                                                   801 
824         bh = sb_bread(sb, ufs_inotofsba(inode-    802         bh = sb_bread(sb, ufs_inotofsba(inode->i_ino));
825         if (!bh) {                                803         if (!bh) {
826                 ufs_warning (sb, "ufs_read_ino    804                 ufs_warning (sb, "ufs_read_inode", "unable to read inode %lu\n", inode->i_ino);
827                 return -1;                        805                 return -1;
828         }                                         806         }
829         if (uspi->fs_magic == UFS2_MAGIC) {       807         if (uspi->fs_magic == UFS2_MAGIC) {
830                 struct ufs2_inode *ufs2_inode     808                 struct ufs2_inode *ufs2_inode = (struct ufs2_inode *)bh->b_data;
831                                                   809 
832                 ufs2_update_inode(inode,          810                 ufs2_update_inode(inode,
833                                   ufs2_inode +    811                                   ufs2_inode + ufs_inotofsbo(inode->i_ino));
834         } else {                                  812         } else {
835                 struct ufs_inode *ufs_inode =     813                 struct ufs_inode *ufs_inode = (struct ufs_inode *) bh->b_data;
836                                                   814 
837                 ufs1_update_inode(inode, ufs_i    815                 ufs1_update_inode(inode, ufs_inode + ufs_inotofsbo(inode->i_ino));
838         }                                         816         }
839                                                   817 
840         mark_buffer_dirty(bh);                    818         mark_buffer_dirty(bh);
841         if (do_sync)                              819         if (do_sync)
842                 sync_dirty_buffer(bh);            820                 sync_dirty_buffer(bh);
843         brelse (bh);                              821         brelse (bh);
844                                                   822 
845         UFSD("EXIT\n");                           823         UFSD("EXIT\n");
846         return 0;                                 824         return 0;
847 }                                                 825 }
848                                                   826 
849 int ufs_write_inode(struct inode *inode, struc    827 int ufs_write_inode(struct inode *inode, struct writeback_control *wbc)
850 {                                                 828 {
851         return ufs_update_inode(inode, wbc->sy    829         return ufs_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
852 }                                                 830 }
853                                                   831 
854 int ufs_sync_inode (struct inode *inode)          832 int ufs_sync_inode (struct inode *inode)
855 {                                                 833 {
856         return ufs_update_inode (inode, 1);       834         return ufs_update_inode (inode, 1);
857 }                                                 835 }
858                                                   836 
859 void ufs_evict_inode(struct inode * inode)        837 void ufs_evict_inode(struct inode * inode)
860 {                                                 838 {
861         int want_delete = 0;                      839         int want_delete = 0;
862                                                   840 
863         if (!inode->i_nlink && !is_bad_inode(i    841         if (!inode->i_nlink && !is_bad_inode(inode))
864                 want_delete = 1;                  842                 want_delete = 1;
865                                                   843 
866         truncate_inode_pages_final(&inode->i_d    844         truncate_inode_pages_final(&inode->i_data);
867         if (want_delete) {                        845         if (want_delete) {
868                 inode->i_size = 0;                846                 inode->i_size = 0;
869                 if (inode->i_blocks &&         !! 847                 if (inode->i_blocks)
870                     (S_ISREG(inode->i_mode) || << 
871                      S_ISLNK(inode->i_mode)))  << 
872                         ufs_truncate_blocks(in    848                         ufs_truncate_blocks(inode);
873                 ufs_update_inode(inode, inode_    849                 ufs_update_inode(inode, inode_needs_sync(inode));
874         }                                         850         }
875                                                   851 
876         invalidate_inode_buffers(inode);          852         invalidate_inode_buffers(inode);
877         clear_inode(inode);                       853         clear_inode(inode);
878                                                   854 
879         if (want_delete)                          855         if (want_delete)
880                 ufs_free_inode(inode);            856                 ufs_free_inode(inode);
881 }                                                 857 }
882                                                   858 
883 struct to_free {                                  859 struct to_free {
884         struct inode *inode;                      860         struct inode *inode;
885         u64 to;                                   861         u64 to;
886         unsigned count;                           862         unsigned count;
887 };                                                863 };
888                                                   864 
889 static inline void free_data(struct to_free *c    865 static inline void free_data(struct to_free *ctx, u64 from, unsigned count)
890 {                                                 866 {
891         if (ctx->count && ctx->to != from) {      867         if (ctx->count && ctx->to != from) {
892                 ufs_free_blocks(ctx->inode, ct    868                 ufs_free_blocks(ctx->inode, ctx->to - ctx->count, ctx->count);
893                 ctx->count = 0;                   869                 ctx->count = 0;
894         }                                         870         }
895         ctx->count += count;                      871         ctx->count += count;
896         ctx->to = from + count;                   872         ctx->to = from + count;
897 }                                                 873 }
898                                                   874 
                                                   >> 875 #define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift)
899 #define DIRECT_FRAGMENT ((inode->i_size + uspi    876 #define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift)
900                                                   877 
901 static void ufs_trunc_direct(struct inode *ino    878 static void ufs_trunc_direct(struct inode *inode)
902 {                                                 879 {
903         struct ufs_inode_info *ufsi = UFS_I(in    880         struct ufs_inode_info *ufsi = UFS_I(inode);
904         struct super_block * sb;                  881         struct super_block * sb;
905         struct ufs_sb_private_info * uspi;        882         struct ufs_sb_private_info * uspi;
906         void *p;                                  883         void *p;
907         u64 frag1, frag2, frag3, frag4, block1    884         u64 frag1, frag2, frag3, frag4, block1, block2;
908         struct to_free ctx = {.inode = inode};    885         struct to_free ctx = {.inode = inode};
909         unsigned i, tmp;                          886         unsigned i, tmp;
910                                                   887 
911         UFSD("ENTER: ino %lu\n", inode->i_ino)    888         UFSD("ENTER: ino %lu\n", inode->i_ino);
912                                                   889 
913         sb = inode->i_sb;                         890         sb = inode->i_sb;
914         uspi = UFS_SB(sb)->s_uspi;                891         uspi = UFS_SB(sb)->s_uspi;
915                                                   892 
916         frag1 = DIRECT_FRAGMENT;                  893         frag1 = DIRECT_FRAGMENT;
917         frag4 = min_t(u64, UFS_NDIR_FRAGMENT,     894         frag4 = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag);
918         frag2 = ((frag1 & uspi->s_fpbmask) ? (    895         frag2 = ((frag1 & uspi->s_fpbmask) ? ((frag1 | uspi->s_fpbmask) + 1) : frag1);
919         frag3 = frag4 & ~uspi->s_fpbmask;         896         frag3 = frag4 & ~uspi->s_fpbmask;
920         block1 = block2 = 0;                      897         block1 = block2 = 0;
921         if (frag2 > frag3) {                      898         if (frag2 > frag3) {
922                 frag2 = frag4;                    899                 frag2 = frag4;
923                 frag3 = frag4 = 0;                900                 frag3 = frag4 = 0;
924         } else if (frag2 < frag3) {               901         } else if (frag2 < frag3) {
925                 block1 = ufs_fragstoblks (frag    902                 block1 = ufs_fragstoblks (frag2);
926                 block2 = ufs_fragstoblks (frag    903                 block2 = ufs_fragstoblks (frag3);
927         }                                         904         }
928                                                   905 
929         UFSD("ino %lu, frag1 %llu, frag2 %llu,    906         UFSD("ino %lu, frag1 %llu, frag2 %llu, block1 %llu, block2 %llu,"
930              " frag3 %llu, frag4 %llu\n", inod    907              " frag3 %llu, frag4 %llu\n", inode->i_ino,
931              (unsigned long long)frag1, (unsig    908              (unsigned long long)frag1, (unsigned long long)frag2,
932              (unsigned long long)block1, (unsi    909              (unsigned long long)block1, (unsigned long long)block2,
933              (unsigned long long)frag3, (unsig    910              (unsigned long long)frag3, (unsigned long long)frag4);
934                                                   911 
935         if (frag1 >= frag2)                       912         if (frag1 >= frag2)
936                 goto next1;                       913                 goto next1;
937                                                   914 
938         /*                                        915         /*
939          * Free first free fragments              916          * Free first free fragments
940          */                                       917          */
941         p = ufs_get_direct_data_ptr(uspi, ufsi    918         p = ufs_get_direct_data_ptr(uspi, ufsi, ufs_fragstoblks(frag1));
942         tmp = ufs_data_ptr_to_cpu(sb, p);         919         tmp = ufs_data_ptr_to_cpu(sb, p);
943         if (!tmp )                                920         if (!tmp )
944                 ufs_panic (sb, "ufs_trunc_dire    921                 ufs_panic (sb, "ufs_trunc_direct", "internal error");
945         frag2 -= frag1;                           922         frag2 -= frag1;
946         frag1 = ufs_fragnum (frag1);              923         frag1 = ufs_fragnum (frag1);
947                                                   924 
948         ufs_free_fragments(inode, tmp + frag1,    925         ufs_free_fragments(inode, tmp + frag1, frag2);
949                                                   926 
950 next1:                                            927 next1:
951         /*                                        928         /*
952          * Free whole blocks                      929          * Free whole blocks
953          */                                       930          */
954         for (i = block1 ; i < block2; i++) {      931         for (i = block1 ; i < block2; i++) {
955                 p = ufs_get_direct_data_ptr(us    932                 p = ufs_get_direct_data_ptr(uspi, ufsi, i);
956                 tmp = ufs_data_ptr_to_cpu(sb,     933                 tmp = ufs_data_ptr_to_cpu(sb, p);
957                 if (!tmp)                         934                 if (!tmp)
958                         continue;                 935                         continue;
959                 write_seqlock(&ufsi->meta_lock    936                 write_seqlock(&ufsi->meta_lock);
960                 ufs_data_ptr_clear(uspi, p);      937                 ufs_data_ptr_clear(uspi, p);
961                 write_sequnlock(&ufsi->meta_lo    938                 write_sequnlock(&ufsi->meta_lock);
962                                                   939 
963                 free_data(&ctx, tmp, uspi->s_f    940                 free_data(&ctx, tmp, uspi->s_fpb);
964         }                                         941         }
965                                                   942 
966         free_data(&ctx, 0, 0);                    943         free_data(&ctx, 0, 0);
967                                                   944 
968         if (frag3 >= frag4)                       945         if (frag3 >= frag4)
969                 goto next3;                       946                 goto next3;
970                                                   947 
971         /*                                        948         /*
972          * Free last free fragments               949          * Free last free fragments
973          */                                       950          */
974         p = ufs_get_direct_data_ptr(uspi, ufsi    951         p = ufs_get_direct_data_ptr(uspi, ufsi, ufs_fragstoblks(frag3));
975         tmp = ufs_data_ptr_to_cpu(sb, p);         952         tmp = ufs_data_ptr_to_cpu(sb, p);
976         if (!tmp )                                953         if (!tmp )
977                 ufs_panic(sb, "ufs_truncate_di    954                 ufs_panic(sb, "ufs_truncate_direct", "internal error");
978         frag4 = ufs_fragnum (frag4);              955         frag4 = ufs_fragnum (frag4);
979         write_seqlock(&ufsi->meta_lock);          956         write_seqlock(&ufsi->meta_lock);
980         ufs_data_ptr_clear(uspi, p);              957         ufs_data_ptr_clear(uspi, p);
981         write_sequnlock(&ufsi->meta_lock);        958         write_sequnlock(&ufsi->meta_lock);
982                                                   959 
983         ufs_free_fragments (inode, tmp, frag4)    960         ufs_free_fragments (inode, tmp, frag4);
984  next3:                                           961  next3:
985                                                   962 
986         UFSD("EXIT: ino %lu\n", inode->i_ino);    963         UFSD("EXIT: ino %lu\n", inode->i_ino);
987 }                                                 964 }
988                                                   965 
989 static void free_full_branch(struct inode *ino    966 static void free_full_branch(struct inode *inode, u64 ind_block, int depth)
990 {                                                 967 {
991         struct super_block *sb = inode->i_sb;     968         struct super_block *sb = inode->i_sb;
992         struct ufs_sb_private_info *uspi = UFS    969         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
993         struct ufs_buffer_head *ubh = ubh_brea    970         struct ufs_buffer_head *ubh = ubh_bread(sb, ind_block, uspi->s_bsize);
994         unsigned i;                               971         unsigned i;
995                                                   972 
996         if (!ubh)                                 973         if (!ubh)
997                 return;                           974                 return;
998                                                   975 
999         if (--depth) {                            976         if (--depth) {
1000                 for (i = 0; i < uspi->s_apb;     977                 for (i = 0; i < uspi->s_apb; i++) {
1001                         void *p = ubh_get_dat    978                         void *p = ubh_get_data_ptr(uspi, ubh, i);
1002                         u64 block = ufs_data_    979                         u64 block = ufs_data_ptr_to_cpu(sb, p);
1003                         if (block)               980                         if (block)
1004                                 free_full_bra    981                                 free_full_branch(inode, block, depth);
1005                 }                                982                 }
1006         } else {                                 983         } else {
1007                 struct to_free ctx = {.inode     984                 struct to_free ctx = {.inode = inode};
1008                                                  985 
1009                 for (i = 0; i < uspi->s_apb;     986                 for (i = 0; i < uspi->s_apb; i++) {
1010                         void *p = ubh_get_dat    987                         void *p = ubh_get_data_ptr(uspi, ubh, i);
1011                         u64 block = ufs_data_    988                         u64 block = ufs_data_ptr_to_cpu(sb, p);
1012                         if (block)               989                         if (block)
1013                                 free_data(&ct    990                                 free_data(&ctx, block, uspi->s_fpb);
1014                 }                                991                 }
1015                 free_data(&ctx, 0, 0);           992                 free_data(&ctx, 0, 0);
1016         }                                        993         }
1017                                                  994 
1018         ubh_bforget(ubh);                        995         ubh_bforget(ubh);
1019         ufs_free_blocks(inode, ind_block, usp    996         ufs_free_blocks(inode, ind_block, uspi->s_fpb);
1020 }                                                997 }
1021                                                  998 
1022 static void free_branch_tail(struct inode *in    999 static void free_branch_tail(struct inode *inode, unsigned from, struct ufs_buffer_head *ubh, int depth)
1023 {                                                1000 {
1024         struct super_block *sb = inode->i_sb;    1001         struct super_block *sb = inode->i_sb;
1025         struct ufs_sb_private_info *uspi = UF    1002         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
1026         unsigned i;                              1003         unsigned i;
1027                                                  1004 
1028         if (--depth) {                           1005         if (--depth) {
1029                 for (i = from; i < uspi->s_ap    1006                 for (i = from; i < uspi->s_apb ; i++) {
1030                         void *p = ubh_get_dat    1007                         void *p = ubh_get_data_ptr(uspi, ubh, i);
1031                         u64 block = ufs_data_    1008                         u64 block = ufs_data_ptr_to_cpu(sb, p);
1032                         if (block) {             1009                         if (block) {
1033                                 write_seqlock    1010                                 write_seqlock(&UFS_I(inode)->meta_lock);
1034                                 ufs_data_ptr_    1011                                 ufs_data_ptr_clear(uspi, p);
1035                                 write_sequnlo    1012                                 write_sequnlock(&UFS_I(inode)->meta_lock);
1036                                 ubh_mark_buff    1013                                 ubh_mark_buffer_dirty(ubh);
1037                                 free_full_bra    1014                                 free_full_branch(inode, block, depth);
1038                         }                        1015                         }
1039                 }                                1016                 }
1040         } else {                                 1017         } else {
1041                 struct to_free ctx = {.inode     1018                 struct to_free ctx = {.inode = inode};
1042                                                  1019 
1043                 for (i = from; i < uspi->s_ap    1020                 for (i = from; i < uspi->s_apb; i++) {
1044                         void *p = ubh_get_dat    1021                         void *p = ubh_get_data_ptr(uspi, ubh, i);
1045                         u64 block = ufs_data_    1022                         u64 block = ufs_data_ptr_to_cpu(sb, p);
1046                         if (block) {             1023                         if (block) {
1047                                 write_seqlock    1024                                 write_seqlock(&UFS_I(inode)->meta_lock);
1048                                 ufs_data_ptr_    1025                                 ufs_data_ptr_clear(uspi, p);
1049                                 write_sequnlo    1026                                 write_sequnlock(&UFS_I(inode)->meta_lock);
1050                                 ubh_mark_buff    1027                                 ubh_mark_buffer_dirty(ubh);
1051                                 free_data(&ct    1028                                 free_data(&ctx, block, uspi->s_fpb);
1052                         }                        1029                         }
1053                 }                                1030                 }
1054                 free_data(&ctx, 0, 0);           1031                 free_data(&ctx, 0, 0);
1055         }                                        1032         }
1056         if (IS_SYNC(inode) && ubh_buffer_dirt    1033         if (IS_SYNC(inode) && ubh_buffer_dirty(ubh))
1057                 ubh_sync_block(ubh);             1034                 ubh_sync_block(ubh);
1058         ubh_brelse(ubh);                         1035         ubh_brelse(ubh);
1059 }                                                1036 }
1060                                                  1037 
1061 static int ufs_alloc_lastblock(struct inode *    1038 static int ufs_alloc_lastblock(struct inode *inode, loff_t size)
1062 {                                                1039 {
1063         int err = 0;                             1040         int err = 0;
1064         struct super_block *sb = inode->i_sb;    1041         struct super_block *sb = inode->i_sb;
1065         struct address_space *mapping = inode    1042         struct address_space *mapping = inode->i_mapping;
1066         struct ufs_sb_private_info *uspi = UF    1043         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
1067         unsigned i, end;                         1044         unsigned i, end;
1068         sector_t lastfrag;                       1045         sector_t lastfrag;
1069         struct folio *folio;                  !! 1046         struct page *lastpage;
1070         struct buffer_head *bh;                  1047         struct buffer_head *bh;
1071         u64 phys64;                              1048         u64 phys64;
1072                                                  1049 
1073         lastfrag = (size + uspi->s_fsize - 1)    1050         lastfrag = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
1074                                                  1051 
1075         if (!lastfrag)                           1052         if (!lastfrag)
1076                 goto out;                        1053                 goto out;
1077                                                  1054 
1078         lastfrag--;                              1055         lastfrag--;
1079                                                  1056 
1080         folio = ufs_get_locked_folio(mapping, !! 1057         lastpage = ufs_get_locked_page(mapping, lastfrag >>
1081                                        (PAGE_    1058                                        (PAGE_SHIFT - inode->i_blkbits));
1082         if (IS_ERR(folio)) {                  !! 1059        if (IS_ERR(lastpage)) {
1083                 err = -EIO;                   !! 1060                err = -EIO;
1084                 goto out;                     !! 1061                goto out;
1085         }                                     !! 1062        }
                                                   >> 1063 
                                                   >> 1064        end = lastfrag & ((1 << (PAGE_SHIFT - inode->i_blkbits)) - 1);
                                                   >> 1065        bh = page_buffers(lastpage);
                                                   >> 1066        for (i = 0; i < end; ++i)
                                                   >> 1067                bh = bh->b_this_page;
1086                                                  1068 
1087         end = lastfrag & ((1 << (PAGE_SHIFT - << 
1088         bh = folio_buffers(folio);            << 
1089         for (i = 0; i < end; ++i)             << 
1090                 bh = bh->b_this_page;         << 
1091                                                  1069 
1092        err = ufs_getfrag_block(inode, lastfra    1070        err = ufs_getfrag_block(inode, lastfrag, bh, 1);
1093                                                  1071 
1094        if (unlikely(err))                        1072        if (unlikely(err))
1095                goto out_unlock;                  1073                goto out_unlock;
1096                                                  1074 
1097        if (buffer_new(bh)) {                     1075        if (buffer_new(bh)) {
1098                clear_buffer_new(bh);             1076                clear_buffer_new(bh);
1099                clean_bdev_bh_alias(bh);       !! 1077                unmap_underlying_metadata(bh->b_bdev,
                                                   >> 1078                                          bh->b_blocknr);
1100                /*                                1079                /*
1101                 * we do not zeroize fragment,    1080                 * we do not zeroize fragment, because of
1102                 * if it maped to hole, it alr    1081                 * if it maped to hole, it already contains zeroes
1103                 */                               1082                 */
1104                set_buffer_uptodate(bh);          1083                set_buffer_uptodate(bh);
1105                mark_buffer_dirty(bh);            1084                mark_buffer_dirty(bh);
1106                 folio_mark_dirty(folio);      !! 1085                set_page_dirty(lastpage);
1107        }                                         1086        }
1108                                                  1087 
1109        if (lastfrag >= UFS_IND_FRAGMENT) {       1088        if (lastfrag >= UFS_IND_FRAGMENT) {
1110                end = uspi->s_fpb - ufs_fragnu    1089                end = uspi->s_fpb - ufs_fragnum(lastfrag) - 1;
1111                phys64 = bh->b_blocknr + 1;       1090                phys64 = bh->b_blocknr + 1;
1112                for (i = 0; i < end; ++i) {       1091                for (i = 0; i < end; ++i) {
1113                        bh = sb_getblk(sb, i +    1092                        bh = sb_getblk(sb, i + phys64);
1114                        lock_buffer(bh);          1093                        lock_buffer(bh);
1115                        memset(bh->b_data, 0,     1094                        memset(bh->b_data, 0, sb->s_blocksize);
1116                        set_buffer_uptodate(bh    1095                        set_buffer_uptodate(bh);
1117                        mark_buffer_dirty(bh);    1096                        mark_buffer_dirty(bh);
1118                        unlock_buffer(bh);        1097                        unlock_buffer(bh);
1119                        sync_dirty_buffer(bh);    1098                        sync_dirty_buffer(bh);
1120                        brelse(bh);               1099                        brelse(bh);
1121                }                                 1100                }
1122        }                                         1101        }
1123 out_unlock:                                      1102 out_unlock:
1124        ufs_put_locked_folio(folio);           !! 1103        ufs_put_locked_page(lastpage);
1125 out:                                             1104 out:
1126        return err;                               1105        return err;
1127 }                                                1106 }
1128                                                  1107 
1129 static void ufs_truncate_blocks(struct inode  !! 1108 static void __ufs_truncate_blocks(struct inode *inode)
1130 {                                                1109 {
1131         struct ufs_inode_info *ufsi = UFS_I(i    1110         struct ufs_inode_info *ufsi = UFS_I(inode);
1132         struct super_block *sb = inode->i_sb;    1111         struct super_block *sb = inode->i_sb;
1133         struct ufs_sb_private_info *uspi = UF    1112         struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
1134         unsigned offsets[4];                     1113         unsigned offsets[4];
1135         int depth;                            !! 1114         int depth = ufs_block_to_path(inode, DIRECT_BLOCK, offsets);
1136         int depth2;                              1115         int depth2;
1137         unsigned i;                              1116         unsigned i;
1138         struct ufs_buffer_head *ubh[3];          1117         struct ufs_buffer_head *ubh[3];
1139         void *p;                                 1118         void *p;
1140         u64 block;                               1119         u64 block;
1141                                                  1120 
1142         if (inode->i_size) {                  !! 1121         if (!depth)
1143                 sector_t last = (inode->i_siz !! 1122                 return;
1144                 depth = ufs_block_to_path(ino << 
1145                 if (!depth)                   << 
1146                         return;               << 
1147         } else {                              << 
1148                 depth = 1;                    << 
1149         }                                     << 
1150                                                  1123 
                                                   >> 1124         /* find the last non-zero in offsets[] */
1151         for (depth2 = depth - 1; depth2; dept    1125         for (depth2 = depth - 1; depth2; depth2--)
1152                 if (offsets[depth2] != uspi-> !! 1126                 if (offsets[depth2])
1153                         break;                   1127                         break;
1154                                                  1128 
1155         mutex_lock(&ufsi->truncate_mutex);       1129         mutex_lock(&ufsi->truncate_mutex);
1156         if (depth == 1) {                        1130         if (depth == 1) {
1157                 ufs_trunc_direct(inode);         1131                 ufs_trunc_direct(inode);
1158                 offsets[0] = UFS_IND_BLOCK;      1132                 offsets[0] = UFS_IND_BLOCK;
1159         } else {                                 1133         } else {
1160                 /* get the blocks that should    1134                 /* get the blocks that should be partially emptied */
1161                 p = ufs_get_direct_data_ptr(u !! 1135                 p = ufs_get_direct_data_ptr(uspi, ufsi, offsets[0]);
1162                 for (i = 0; i < depth2; i++)     1136                 for (i = 0; i < depth2; i++) {
                                                   >> 1137                         offsets[i]++;   /* next branch is fully freed */
1163                         block = ufs_data_ptr_    1138                         block = ufs_data_ptr_to_cpu(sb, p);
1164                         if (!block)              1139                         if (!block)
1165                                 break;           1140                                 break;
1166                         ubh[i] = ubh_bread(sb    1141                         ubh[i] = ubh_bread(sb, block, uspi->s_bsize);
1167                         if (!ubh[i]) {           1142                         if (!ubh[i]) {
1168                                 write_seqlock    1143                                 write_seqlock(&ufsi->meta_lock);
1169                                 ufs_data_ptr_    1144                                 ufs_data_ptr_clear(uspi, p);
1170                                 write_sequnlo    1145                                 write_sequnlock(&ufsi->meta_lock);
1171                                 break;           1146                                 break;
1172                         }                        1147                         }
1173                         p = ubh_get_data_ptr( !! 1148                         p = ubh_get_data_ptr(uspi, ubh[i], offsets[i + 1]);
1174                 }                                1149                 }
1175                 while (i--)                      1150                 while (i--)
1176                         free_branch_tail(inod    1151                         free_branch_tail(inode, offsets[i + 1], ubh[i], depth - i - 1);
1177         }                                        1152         }
1178         for (i = offsets[0]; i <= UFS_TIND_BL    1153         for (i = offsets[0]; i <= UFS_TIND_BLOCK; i++) {
1179                 p = ufs_get_direct_data_ptr(u    1154                 p = ufs_get_direct_data_ptr(uspi, ufsi, i);
1180                 block = ufs_data_ptr_to_cpu(s    1155                 block = ufs_data_ptr_to_cpu(sb, p);
1181                 if (block) {                     1156                 if (block) {
1182                         write_seqlock(&ufsi->    1157                         write_seqlock(&ufsi->meta_lock);
1183                         ufs_data_ptr_clear(us    1158                         ufs_data_ptr_clear(uspi, p);
1184                         write_sequnlock(&ufsi    1159                         write_sequnlock(&ufsi->meta_lock);
1185                         free_full_branch(inod    1160                         free_full_branch(inode, block, i - UFS_IND_BLOCK + 1);
1186                 }                                1161                 }
1187         }                                        1162         }
1188         read_seqlock_excl(&ufsi->meta_lock);  << 
1189         ufsi->i_lastfrag = DIRECT_FRAGMENT;      1163         ufsi->i_lastfrag = DIRECT_FRAGMENT;
1190         read_sequnlock_excl(&ufsi->meta_lock) << 
1191         mark_inode_dirty(inode);                 1164         mark_inode_dirty(inode);
1192         mutex_unlock(&ufsi->truncate_mutex);     1165         mutex_unlock(&ufsi->truncate_mutex);
1193 }                                                1166 }
1194                                                  1167 
1195 static int ufs_truncate(struct inode *inode,     1168 static int ufs_truncate(struct inode *inode, loff_t size)
1196 {                                                1169 {
1197         int err = 0;                             1170         int err = 0;
1198                                                  1171 
1199         UFSD("ENTER: ino %lu, i_size: %llu, o    1172         UFSD("ENTER: ino %lu, i_size: %llu, old_i_size: %llu\n",
1200              inode->i_ino, (unsigned long lon    1173              inode->i_ino, (unsigned long long)size,
1201              (unsigned long long)i_size_read(    1174              (unsigned long long)i_size_read(inode));
1202                                                  1175 
1203         if (!(S_ISREG(inode->i_mode) || S_ISD    1176         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1204               S_ISLNK(inode->i_mode)))           1177               S_ISLNK(inode->i_mode)))
1205                 return -EINVAL;                  1178                 return -EINVAL;
1206         if (IS_APPEND(inode) || IS_IMMUTABLE(    1179         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1207                 return -EPERM;                   1180                 return -EPERM;
1208                                                  1181 
1209         err = ufs_alloc_lastblock(inode, size    1182         err = ufs_alloc_lastblock(inode, size);
1210                                                  1183 
1211         if (err)                                 1184         if (err)
1212                 goto out;                        1185                 goto out;
1213                                                  1186 
1214         block_truncate_page(inode->i_mapping,    1187         block_truncate_page(inode->i_mapping, size, ufs_getfrag_block);
1215                                                  1188 
1216         truncate_setsize(inode, size);           1189         truncate_setsize(inode, size);
1217                                                  1190 
1218         ufs_truncate_blocks(inode);           !! 1191         __ufs_truncate_blocks(inode);
1219         inode_set_mtime_to_ts(inode, inode_se !! 1192         inode->i_mtime = inode->i_ctime = current_time(inode);
1220         mark_inode_dirty(inode);                 1193         mark_inode_dirty(inode);
1221 out:                                             1194 out:
1222         UFSD("EXIT: err %d\n", err);             1195         UFSD("EXIT: err %d\n", err);
1223         return err;                              1196         return err;
1224 }                                                1197 }
1225                                                  1198 
1226 int ufs_setattr(struct mnt_idmap *idmap, stru !! 1199 void ufs_truncate_blocks(struct inode *inode)
1227                 struct iattr *attr)           !! 1200 {
                                                   >> 1201         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
                                                   >> 1202               S_ISLNK(inode->i_mode)))
                                                   >> 1203                 return;
                                                   >> 1204         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
                                                   >> 1205                 return;
                                                   >> 1206         __ufs_truncate_blocks(inode);
                                                   >> 1207 }
                                                   >> 1208 
                                                   >> 1209 int ufs_setattr(struct dentry *dentry, struct iattr *attr)
1228 {                                                1210 {
1229         struct inode *inode = d_inode(dentry)    1211         struct inode *inode = d_inode(dentry);
1230         unsigned int ia_valid = attr->ia_vali    1212         unsigned int ia_valid = attr->ia_valid;
1231         int error;                               1213         int error;
1232                                                  1214 
1233         error = setattr_prepare(&nop_mnt_idma !! 1215         error = setattr_prepare(dentry, attr);
1234         if (error)                               1216         if (error)
1235                 return error;                    1217                 return error;
1236                                                  1218 
1237         if (ia_valid & ATTR_SIZE && attr->ia_    1219         if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
1238                 error = ufs_truncate(inode, a    1220                 error = ufs_truncate(inode, attr->ia_size);
1239                 if (error)                       1221                 if (error)
1240                         return error;            1222                         return error;
1241         }                                        1223         }
1242                                                  1224 
1243         setattr_copy(&nop_mnt_idmap, inode, a !! 1225         setattr_copy(inode, attr);
1244         mark_inode_dirty(inode);                 1226         mark_inode_dirty(inode);
1245         return 0;                                1227         return 0;
1246 }                                                1228 }
1247                                                  1229 
1248 const struct inode_operations ufs_file_inode_    1230 const struct inode_operations ufs_file_inode_operations = {
1249         .setattr = ufs_setattr,                  1231         .setattr = ufs_setattr,
1250 };                                               1232 };
1251                                                  1233 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php