2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ialloc.c
|
|
|
|
*
|
|
|
|
* PURPOSE
|
|
|
|
* Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
|
|
|
|
*
|
|
|
|
* COPYRIGHT
|
|
|
|
* This file is distributed under the terms of the GNU General Public
|
|
|
|
* License (GPL). Copies of the GPL can be obtained from:
|
|
|
|
* ftp://prep.ai.mit.edu/pub/gnu/GPL
|
|
|
|
* Each contributing author retains all rights to their own work.
|
|
|
|
*
|
|
|
|
* (C) 1998-2001 Ben Fennema
|
|
|
|
*
|
|
|
|
* HISTORY
|
|
|
|
*
|
|
|
|
* 02/24/99 blf Created.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "udfdecl.h"
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include "udf_i.h"
|
|
|
|
#include "udf_sb.h"
|
|
|
|
|
2007-07-19 16:47:43 +08:00
|
|
|
void udf_free_inode(struct inode *inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2013-09-13 04:00:15 +08:00
|
|
|
struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-13 04:00:15 +08:00
|
|
|
if (lvidiu) {
|
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (S_ISDIR(inode->i_mode))
|
2008-01-31 05:03:57 +08:00
|
|
|
le32_add_cpu(&lvidiu->numDirs, -1);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-01-31 05:03:57 +08:00
|
|
|
le32_add_cpu(&lvidiu->numFiles, -1);
|
2009-03-17 01:27:37 +08:00
|
|
|
udf_updated_lvid(sb);
|
2013-09-13 04:00:15 +08:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-15 18:29:03 +08:00
|
|
|
udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-09-04 21:47:41 +08:00
|
|
|
struct inode *udf_new_inode(struct inode *dir, umode_t mode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2007-07-19 16:47:43 +08:00
|
|
|
struct inode *inode;
|
2017-10-12 21:48:40 +08:00
|
|
|
udf_pblk_t block;
|
2008-02-08 20:20:42 +08:00
|
|
|
uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
|
2008-02-08 20:20:44 +08:00
|
|
|
struct udf_inode_info *iinfo;
|
|
|
|
struct udf_inode_info *dinfo = UDF_I(dir);
|
2013-09-13 04:00:15 +08:00
|
|
|
struct logicalVolIntegrityDescImpUse *lvidiu;
|
2014-09-04 21:47:41 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
inode = new_inode(sb);
|
|
|
|
|
2014-09-04 21:47:41 +08:00
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo = UDF_I(inode);
|
2008-08-18 19:44:48 +08:00
|
|
|
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
|
|
|
|
iinfo->i_efe = 1;
|
|
|
|
if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
|
|
|
|
sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
|
|
|
|
iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
|
|
|
|
sizeof(struct extendedFileEntry),
|
|
|
|
GFP_KERNEL);
|
|
|
|
} else {
|
|
|
|
iinfo->i_efe = 0;
|
|
|
|
iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
|
|
|
|
sizeof(struct fileEntry),
|
|
|
|
GFP_KERNEL);
|
|
|
|
}
|
|
|
|
if (!iinfo->i_ext.i_data) {
|
|
|
|
iput(inode);
|
2014-09-04 21:47:41 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2008-08-18 19:44:48 +08:00
|
|
|
}
|
2006-08-06 03:15:17 +08:00
|
|
|
|
2014-09-04 21:47:41 +08:00
|
|
|
err = -ENOSPC;
|
2008-02-08 20:20:36 +08:00
|
|
|
block = udf_new_block(dir->i_sb, NULL,
|
2008-02-08 20:20:44 +08:00
|
|
|
dinfo->i_location.partitionReferenceNum,
|
2014-09-04 21:47:41 +08:00
|
|
|
start, &err);
|
|
|
|
if (err) {
|
2005-04-17 06:20:36 +08:00
|
|
|
iput(inode);
|
2014-09-04 21:47:41 +08:00
|
|
|
return ERR_PTR(err);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 04:00:15 +08:00
|
|
|
lvidiu = udf_sb_lvidiu(sb);
|
|
|
|
if (lvidiu) {
|
2010-10-21 00:28:46 +08:00
|
|
|
iinfo->i_unique = lvid_get_unique_id(sb);
|
2014-09-04 22:26:19 +08:00
|
|
|
inode->i_generation = iinfo->i_unique;
|
2010-10-21 00:28:46 +08:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (S_ISDIR(mode))
|
2008-01-31 05:03:57 +08:00
|
|
|
le32_add_cpu(&lvidiu->numDirs, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-01-31 05:03:57 +08:00
|
|
|
le32_add_cpu(&lvidiu->numFiles, 1);
|
2009-03-17 01:27:37 +08:00
|
|
|
udf_updated_lvid(sb);
|
2010-10-21 00:28:46 +08:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-03-04 22:32:22 +08:00
|
|
|
|
|
|
|
inode_init_owner(inode, dir, mode);
|
2018-02-22 00:59:31 +08:00
|
|
|
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
|
|
|
|
inode->i_uid = sbi->s_uid;
|
|
|
|
if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
|
|
|
|
inode->i_gid = sbi->s_gid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo->i_location.logicalBlockNum = block;
|
|
|
|
iinfo->i_location.partitionReferenceNum =
|
|
|
|
dinfo->i_location.partitionReferenceNum;
|
2008-10-15 18:29:03 +08:00
|
|
|
inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
inode->i_blocks = 0;
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo->i_lenEAttr = 0;
|
|
|
|
iinfo->i_lenAlloc = 0;
|
|
|
|
iinfo->i_use = 0;
|
2012-02-14 13:28:42 +08:00
|
|
|
iinfo->i_checkpoint = 1;
|
2019-08-27 20:13:59 +08:00
|
|
|
iinfo->i_extraPerms = FE_PERM_U_CHATTR;
|
|
|
|
udf_update_extra_perms(inode, mode);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-02-08 20:20:44 +08:00
|
|
|
iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
2018-06-20 16:15:13 +08:00
|
|
|
iinfo->i_crtime = inode->i_mtime;
|
2014-09-04 21:38:11 +08:00
|
|
|
if (unlikely(insert_inode_locked(inode) < 0)) {
|
|
|
|
make_bad_inode(inode);
|
|
|
|
iput(inode);
|
2014-09-04 21:47:41 +08:00
|
|
|
return ERR_PTR(-EIO);
|
2014-09-04 21:38:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
|
|
|
return inode;
|
|
|
|
}
|