Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/adfs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 1997-1999 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "adfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Lookup/Create a block at offset 'block' into 'inode'.  We currently do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * not support creation of new blocks, so we return -EIO for this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) adfs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	       int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	if (!create) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		if (block >= inode->i_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 			goto abort_toobig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		block = __adfs_block_map(inode->i_sb, ADFS_I(inode)->indaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 					 block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		if (block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			map_bh(bh, inode->i_sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	/* don't support allocation of blocks yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) abort_toobig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int adfs_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return block_write_full_page(page, adfs_get_block, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int adfs_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return block_read_full_page(page, adfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static void adfs_write_failed(struct address_space *mapping, loff_t to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (to > inode->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		truncate_pagecache(inode, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int adfs_write_begin(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			loff_t pos, unsigned len, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			struct page **pagep, void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	*pagep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				adfs_get_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				&ADFS_I(mapping->host)->mmu_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		adfs_write_failed(mapping, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static sector_t _adfs_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return generic_block_bmap(mapping, block, adfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static const struct address_space_operations adfs_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.readpage	= adfs_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.writepage	= adfs_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.write_begin	= adfs_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.write_end	= generic_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.bmap		= _adfs_bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Convert ADFS attributes and filetype to Linux permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static umode_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) adfs_atts2mode(struct super_block *sb, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned int attr = ADFS_I(inode)->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	umode_t mode, rmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct adfs_sb_info *asb = ADFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (attr & ADFS_NDA_DIRECTORY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		mode = S_IRUGO & asb->s_owner_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return S_IFDIR | S_IXUGO | mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	switch (adfs_filetype(ADFS_I(inode)->loadaddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case 0xfc0:	/* LinkFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return S_IFLNK|S_IRWXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case 0xfe6:	/* UnixExec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		rmask = S_IRUGO | S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		rmask = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	mode = S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (attr & ADFS_NDA_OWNER_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		mode |= rmask & asb->s_owner_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (attr & ADFS_NDA_OWNER_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		mode |= S_IWUGO & asb->s_owner_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (attr & ADFS_NDA_PUBLIC_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		mode |= rmask & asb->s_other_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (attr & ADFS_NDA_PUBLIC_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		mode |= S_IWUGO & asb->s_other_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * Convert Linux permission to ADFS attribute.  We try to do the reverse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * of atts2mode, but there is not a 1:1 translation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int adfs_mode2atts(struct super_block *sb, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			  umode_t ia_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct adfs_sb_info *asb = ADFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* FIXME: should we be able to alter a link? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return ADFS_I(inode)->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* Directories do not have read/write permissions on the media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return ADFS_NDA_DIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	attr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mode = ia_mode & asb->s_owner_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (mode & S_IRUGO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		attr |= ADFS_NDA_OWNER_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (mode & S_IWUGO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		attr |= ADFS_NDA_OWNER_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	mode = ia_mode & asb->s_other_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	mode &= ~asb->s_owner_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (mode & S_IRUGO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		attr |= ADFS_NDA_PUBLIC_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (mode & S_IWUGO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		attr |= ADFS_NDA_PUBLIC_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static const s64 nsec_unix_epoch_diff_risc_os_epoch = 2208988800000000000LL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * Convert an ADFS time to Unix time.  ADFS has a 40-bit centi-second time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * referenced to 1 Jan 1900 (til 2248) so we need to discard 2208988800 seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * of time to convert from RISC OS epoch to Unix epoch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) adfs_adfs2unix_time(struct timespec64 *tv, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	unsigned int high, low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* 01 Jan 1970 00:00:00 (Unix epoch) as nanoseconds since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * 01 Jan 1900 00:00:00 (RISC OS epoch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	s64 nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (!adfs_inode_is_stamped(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto cur_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	high = ADFS_I(inode)->loadaddr & 0xFF; /* top 8 bits of timestamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	low  = ADFS_I(inode)->execaddr;    /* bottom 32 bits of timestamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* convert 40-bit centi-seconds to 32-bit seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * going via nanoseconds to retain precision
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	nsec = (((s64) high << 32) | (s64) low) * 10000000; /* cs to ns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* Files dated pre  01 Jan 1970 00:00:00. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (nsec < nsec_unix_epoch_diff_risc_os_epoch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto too_early;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/* convert from RISC OS to Unix epoch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	nsec -= nsec_unix_epoch_diff_risc_os_epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	*tv = ns_to_timespec64(nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  cur_time:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	*tv = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  too_early:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	tv->tv_sec = tv->tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Convert an Unix time to ADFS time for an entry that is already stamped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static void adfs_unix2adfs_time(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				const struct timespec64 *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	s64 cs, nsec = timespec64_to_ns(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/* convert from Unix to RISC OS epoch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	nsec += nsec_unix_epoch_diff_risc_os_epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* convert from nanoseconds to centiseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	cs = div_s64(nsec, 10000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	cs = clamp_t(s64, cs, 0, 0xffffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	ADFS_I(inode)->loadaddr &= ~0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	ADFS_I(inode)->loadaddr |= (cs >> 32) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	ADFS_I(inode)->execaddr = cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Fill in the inode information from the object information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * Note that this is an inode-less filesystem, so we can't use the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * number to reference the metadata on the media.  Instead, we use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * inode number to hold the object ID, which in turn will tell us where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * the data is held.  We also save the parent object ID, and with these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * two, we can locate the metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * This does mean that we rely on an objects parent remaining the same at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * all times - we cannot cope with a cross-directory rename (yet).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) adfs_iget(struct super_block *sb, struct object_info *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	inode->i_uid	 = ADFS_SB(sb)->s_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	inode->i_gid	 = ADFS_SB(sb)->s_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	inode->i_ino	 = obj->indaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	inode->i_size	 = obj->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	inode->i_blocks	 = (inode->i_size + sb->s_blocksize - 1) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			    sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 * we need to save the parent directory ID so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * write_inode can update the directory information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * for this file.  This will need special handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * for cross-directory renames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	ADFS_I(inode)->parent_id = obj->parent_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ADFS_I(inode)->indaddr   = obj->indaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	ADFS_I(inode)->loadaddr  = obj->loadaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ADFS_I(inode)->execaddr  = obj->execaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	ADFS_I(inode)->attr      = obj->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	inode->i_mode	 = adfs_atts2mode(sb, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	adfs_adfs2unix_time(&inode->i_mtime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	inode->i_atime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	inode->i_ctime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		inode->i_op	= &adfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		inode->i_fop	= &adfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	} else if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		inode->i_op	= &adfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		inode->i_fop	= &adfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		inode->i_mapping->a_ops = &adfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		ADFS_I(inode)->mmu_private = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	inode_fake_hash(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * Validate and convert a changed access mode/time to their ADFS equivalents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * adfs_write_inode will actually write the information back to the directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) adfs_notify_change(struct dentry *dentry, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	unsigned int ia_valid = attr->ia_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	error = setattr_prepare(dentry, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * we can't change the UID or GID of any file -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * we have a global UID/GID in the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, ADFS_SB(sb)->s_uid)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	    (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, ADFS_SB(sb)->s_gid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* XXX: this is missing some actual on-disk truncation.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (ia_valid & ATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		truncate_setsize(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (ia_valid & ATTR_MTIME && adfs_inode_is_stamped(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		adfs_unix2adfs_time(inode, &attr->ia_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		adfs_adfs2unix_time(&inode->i_mtime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * FIXME: should we make these == to i_mtime since we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 * have the ability to represent them in our filesystem?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (ia_valid & ATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		inode->i_atime = attr->ia_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (ia_valid & ATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		inode->i_ctime = attr->ia_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		ADFS_I(inode)->attr = adfs_mode2atts(sb, inode, attr->ia_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		inode->i_mode = adfs_atts2mode(sb, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	 * FIXME: should we be marking this inode dirty even if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	 * we don't have any metadata to write back?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (ia_valid & (ATTR_SIZE | ATTR_MTIME | ATTR_MODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * write an existing inode back to the directory, and therefore the disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * The adfs-specific inode data has already been updated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * adfs_notify_change()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int adfs_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	struct object_info obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	obj.indaddr	= ADFS_I(inode)->indaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	obj.name_len	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	obj.parent_id	= ADFS_I(inode)->parent_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	obj.loadaddr	= ADFS_I(inode)->loadaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	obj.execaddr	= ADFS_I(inode)->execaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	obj.attr	= ADFS_I(inode)->attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	obj.size	= inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	ret = adfs_dir_update(sb, &obj, wbc->sync_mode == WB_SYNC_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }