5 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
8 * E-mail regarding any portion of the Linux UDF file system should be
9 * directed to the development team mailing list (run by majordomo):
10 * linux_udf@hpesjro.fc.hp.com
13 * This file is distributed under the terms of the GNU General Public
14 * License (GPL). Copies of the GPL can be obtained from:
15 * ftp://prep.ai.mit.edu/pub/gnu/GPL
16 * Each contributing author retains all rights to their own work.
18 * (C) 1998-2001 Ben Fennema
22 * 02/24/99 blf Created.
28 #include <linux/quotaops.h>
29 #include <linux/udf_fs.h>
30 #include <linux/sched.h>
31 #include <linux/slab.h>
36 void udf_free_inode(struct inode
* inode
)
38 struct super_block
*sb
= inode
->i_sb
;
39 struct udf_sb_info
*sbi
= UDF_SB(sb
);
42 * Note: we must free any quota before locking the superblock,
43 * as writing the quota to disk may need the lock as well.
45 DQUOT_FREE_INODE(inode
);
50 down(&sbi
->s_alloc_sem
);
52 if (S_ISDIR(inode
->i_mode
))
53 UDF_SB_LVIDIU(sb
)->numDirs
=
54 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
) - 1);
56 UDF_SB_LVIDIU(sb
)->numFiles
=
57 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) - 1);
59 mark_buffer_dirty(sbi
->s_lvidbh
);
61 up(&sbi
->s_alloc_sem
);
63 udf_free_blocks(sb
, NULL
, UDF_I_LOCATION(inode
), 0, 1);
66 struct inode
* udf_new_inode (struct inode
*dir
, int mode
, int * err
)
68 struct super_block
*sb
= dir
->i_sb
;
69 struct udf_sb_info
*sbi
= UDF_SB(sb
);
72 uint32_t start
= UDF_I_LOCATION(dir
).logicalBlockNum
;
74 inode
= new_inode(sb
);
83 block
= udf_new_block(dir
->i_sb
, NULL
, UDF_I_LOCATION(dir
).partitionReferenceNum
,
91 down(&sbi
->s_alloc_sem
);
92 UDF_I_UNIQUE(inode
) = 0;
93 UDF_I_LENEXTENTS(inode
) = 0;
94 UDF_I_NEXT_ALLOC_BLOCK(inode
) = 0;
95 UDF_I_NEXT_ALLOC_GOAL(inode
) = 0;
96 UDF_I_STRAT4096(inode
) = 0;
97 if (UDF_SB_LVIDBH(sb
))
99 struct logicalVolHeaderDesc
*lvhd
;
101 lvhd
= (struct logicalVolHeaderDesc
*)(UDF_SB_LVID(sb
)->logicalVolContentsUse
);
103 UDF_SB_LVIDIU(sb
)->numDirs
=
104 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
) + 1);
106 UDF_SB_LVIDIU(sb
)->numFiles
=
107 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) + 1);
108 UDF_I_UNIQUE(inode
) = uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
109 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
111 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
112 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
114 inode
->i_mode
= mode
;
115 inode
->i_uid
= current
->fsuid
;
116 if (dir
->i_mode
& S_ISGID
)
118 inode
->i_gid
= dir
->i_gid
;
123 inode
->i_gid
= current
->fsgid
;
125 UDF_I_LOCATION(inode
).logicalBlockNum
= block
;
126 UDF_I_LOCATION(inode
).partitionReferenceNum
= UDF_I_LOCATION(dir
).partitionReferenceNum
;
127 inode
->i_ino
= udf_get_lb_pblock(sb
, UDF_I_LOCATION(inode
), 0);
128 inode
->i_blksize
= PAGE_SIZE
;
130 UDF_I_LENEATTR(inode
) = 0;
131 UDF_I_LENALLOC(inode
) = 0;
132 UDF_I_USE(inode
) = 0;
133 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
))
135 UDF_I_EFE(inode
) = 1;
136 UDF_UPDATE_UDFREV(inode
->i_sb
, UDF_VERS_USE_EXTENDED_FE
);
137 UDF_I_DATA(inode
) = kmalloc(inode
->i_sb
->s_blocksize
- sizeof(struct extendedFileEntry
), GFP_KERNEL
);
138 memset(UDF_I_DATA(inode
), 0x00, inode
->i_sb
->s_blocksize
- sizeof(struct extendedFileEntry
));
142 UDF_I_EFE(inode
) = 0;
143 UDF_I_DATA(inode
) = kmalloc(inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
), GFP_KERNEL
);
144 memset(UDF_I_DATA(inode
), 0x00, inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
));
146 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
147 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_IN_ICB
;
148 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
149 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_SHORT
;
151 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_LONG
;
152 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
153 UDF_I_CRTIME(inode
) = current_fs_time(inode
->i_sb
);
154 insert_inode_hash(inode
);
155 mark_inode_dirty(inode
);
156 up(&sbi
->s_alloc_sem
);
158 if (DQUOT_ALLOC_INODE(inode
))
161 inode
->i_flags
|= S_NOQUOTA
;