Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#include <linux/buffer_head.h>
  3#include <linux/fs.h>
  4#include <linux/adfs_fs.h>
  5
  6/* Internal data structures for ADFS */
  7
  8#define ADFS_FREE_FRAG		 0
  9#define ADFS_BAD_FRAG		 1
 10#define ADFS_ROOT_FRAG		 2
 11
 12#define ADFS_FILETYPE_NONE	((u16)~0)
 13
 14/* RISC OS 12-bit filetype is stored in load_address[19:8] */
 15static inline u16 adfs_filetype(u32 loadaddr)
 16{
 17	return (loadaddr & 0xfff00000) == 0xfff00000 ?
 18	       (loadaddr >> 8) & 0xfff : ADFS_FILETYPE_NONE;
 19}
 20
 21#define ADFS_NDA_OWNER_READ	(1 << 0)
 22#define ADFS_NDA_OWNER_WRITE	(1 << 1)
 23#define ADFS_NDA_LOCKED		(1 << 2)
 24#define ADFS_NDA_DIRECTORY	(1 << 3)
 25#define ADFS_NDA_EXECUTE	(1 << 4)
 26#define ADFS_NDA_PUBLIC_READ	(1 << 5)
 27#define ADFS_NDA_PUBLIC_WRITE	(1 << 6)
 28
 29#include "dir_f.h"
 30
 
 
 31/*
 32 * adfs file system inode data in memory
 33 */
 34struct adfs_inode_info {
 35	loff_t		mmu_private;
 36	__u32		parent_id;	/* parent indirect disc address	*/
 37	__u32		loadaddr;	/* RISC OS load address		*/
 38	__u32		execaddr;	/* RISC OS exec address		*/
 
 39	unsigned int	attr;		/* RISC OS permissions		*/
 
 40	struct inode vfs_inode;
 41};
 42
 43static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
 44{
 45	return container_of(inode, struct adfs_inode_info, vfs_inode);
 46}
 47
 48static inline bool adfs_inode_is_stamped(struct inode *inode)
 49{
 50	return (ADFS_I(inode)->loadaddr & 0xfff00000) == 0xfff00000;
 51}
 52
 53/*
 54 * Forward-declare this
 55 */
 56struct adfs_discmap;
 57struct adfs_dir_ops;
 58
 59/*
 60 * ADFS file system superblock data in memory
 61 */
 62struct adfs_sb_info {
 63	union { struct {
 64		struct adfs_discmap *s_map;	/* bh list containing map */
 65		const struct adfs_dir_ops *s_dir; /* directory operations */
 66		};
 67		struct rcu_head rcu;	/* used only at shutdown time	 */
 68	};
 69	kuid_t		s_uid;		/* owner uid */
 70	kgid_t		s_gid;		/* owner gid */
 71	umode_t		s_owner_mask;	/* ADFS owner perm -> unix perm */
 72	umode_t		s_other_mask;	/* ADFS other perm -> unix perm	*/
 73	int		s_ftsuffix;	/* ,xyz hex filetype suffix option */
 74
 75	__u32		s_ids_per_zone;	/* max. no ids in one zone */
 76	__u32		s_idlen;	/* length of ID in map */
 77	__u32		s_map_size;	/* sector size of a map	*/
 
 78	signed int	s_map2blk;	/* shift left by this for map->sector*/
 79	unsigned int	s_log2sharesize;/* log2 share size */
 
 80	unsigned int	s_namelen;	/* maximum number of characters in name	 */
 81};
 82
 83static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
 84{
 85	return sb->s_fs_info;
 86}
 87
 
 
 
 
 
 88/*
 89 * Directory handling
 90 */
 91struct adfs_dir {
 92	struct super_block	*sb;
 93
 94	int			nr_buffers;
 95	struct buffer_head	*bh[4];
 96
 97	/* big directories need allocated buffers */
 98	struct buffer_head	**bh_fplus;
 99
100	unsigned int		pos;
101	__u32			parent_id;
102
103	struct adfs_dirheader	dirhead;
104	union  adfs_dirtail	dirtail;
105};
106
107/*
108 * This is the overall maximum name length
109 */
110#define ADFS_MAX_NAME_LEN	(256 + 4) /* +4 for ,xyz hex filetype suffix */
111struct object_info {
112	__u32		parent_id;		/* parent object id	*/
113	__u32		indaddr;		/* indirect disc addr	*/
114	__u32		loadaddr;		/* load address		*/
115	__u32		execaddr;		/* execution address	*/
116	__u32		size;			/* size			*/
117	__u8		attr;			/* RISC OS attributes	*/
118	unsigned int	name_len;		/* name length		*/
119	char		name[ADFS_MAX_NAME_LEN];/* file name		*/
 
 
 
120};
121
 
 
 
 
 
 
 
 
 
 
 
 
 
122struct adfs_dir_ops {
123	int	(*read)(struct super_block *sb, unsigned int indaddr,
124			unsigned int size, struct adfs_dir *dir);
125	int	(*setpos)(struct adfs_dir *dir, unsigned int fpos);
126	int	(*getnext)(struct adfs_dir *dir, struct object_info *obj);
127	int	(*update)(struct adfs_dir *dir, struct object_info *obj);
128	int	(*create)(struct adfs_dir *dir, struct object_info *obj);
129	int	(*remove)(struct adfs_dir *dir, struct object_info *obj);
130	int	(*sync)(struct adfs_dir *dir);
131	void	(*free)(struct adfs_dir *dir);
132};
133
134struct adfs_discmap {
135	struct buffer_head	*dm_bh;
136	__u32			dm_startblk;
137	unsigned int		dm_startbit;
138	unsigned int		dm_endbit;
139};
140
141/* Inode stuff */
142struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
143int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
144int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
145
146/* map.c */
147int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
148extern unsigned int adfs_map_free(struct super_block *sb);
149
150/* Misc */
151__printf(3, 4)
152void __adfs_error(struct super_block *sb, const char *function,
153		  const char *fmt, ...);
154#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
155void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
156
157/* super.c */
158
159/*
160 * Inodes and file operations
161 */
162
163/* dir_*.c */
164extern const struct inode_operations adfs_dir_inode_operations;
165extern const struct file_operations adfs_dir_operations;
166extern const struct dentry_operations adfs_dentry_operations;
167extern const struct adfs_dir_ops adfs_f_dir_ops;
168extern const struct adfs_dir_ops adfs_fplus_dir_ops;
169
170void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
171extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
172			   int wait);
173
174/* file.c */
175extern const struct inode_operations adfs_file_inode_operations;
176extern const struct file_operations adfs_file_operations;
177
178static inline __u32 signed_asl(__u32 val, signed int shift)
179{
180	if (shift >= 0)
181		val <<= shift;
182	else
183		val >>= -shift;
184	return val;
185}
186
187/*
188 * Calculate the address of a block in an object given the block offset
189 * and the object identity.
190 *
191 * The root directory ID should always be looked up in the map [3.4]
192 */
193static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
194				   unsigned int block)
 
195{
196	if (indaddr & 255) {
197		unsigned int off;
198
199		off = (indaddr & 255) - 1;
200		block += off << ADFS_SB(sb)->s_log2sharesize;
201	}
202
203	return adfs_map_lookup(sb, indaddr >> 8, block);
204}
205
206/* Return the disc record from the map */
207static inline
208struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
209{
210	return (void *)(dm[0].dm_bh->b_data + 4);
211}
212
213static inline u64 adfs_disc_size(const struct adfs_discrecord *dr)
214{
215	return (u64)le32_to_cpu(dr->disc_size_high) << 32 |
216		    le32_to_cpu(dr->disc_size);
217}
v4.10.11
 
 
  1#include <linux/fs.h>
  2#include <linux/adfs_fs.h>
  3
  4/* Internal data structures for ADFS */
  5
  6#define ADFS_FREE_FRAG		 0
  7#define ADFS_BAD_FRAG		 1
  8#define ADFS_ROOT_FRAG		 2
  9
 
 
 
 
 
 
 
 
 
 10#define ADFS_NDA_OWNER_READ	(1 << 0)
 11#define ADFS_NDA_OWNER_WRITE	(1 << 1)
 12#define ADFS_NDA_LOCKED		(1 << 2)
 13#define ADFS_NDA_DIRECTORY	(1 << 3)
 14#define ADFS_NDA_EXECUTE	(1 << 4)
 15#define ADFS_NDA_PUBLIC_READ	(1 << 5)
 16#define ADFS_NDA_PUBLIC_WRITE	(1 << 6)
 17
 18#include "dir_f.h"
 19
 20struct buffer_head;
 21
 22/*
 23 * adfs file system inode data in memory
 24 */
 25struct adfs_inode_info {
 26	loff_t		mmu_private;
 27	unsigned long	parent_id;	/* object id of parent		*/
 28	__u32		loadaddr;	/* RISC OS load address		*/
 29	__u32		execaddr;	/* RISC OS exec address		*/
 30	unsigned int	filetype;	/* RISC OS file type		*/
 31	unsigned int	attr;		/* RISC OS permissions		*/
 32	unsigned int	stamped:1;	/* RISC OS file has date/time	*/
 33	struct inode vfs_inode;
 34};
 35
 
 
 
 
 
 
 
 
 
 
 36/*
 37 * Forward-declare this
 38 */
 39struct adfs_discmap;
 40struct adfs_dir_ops;
 41
 42/*
 43 * ADFS file system superblock data in memory
 44 */
 45struct adfs_sb_info {
 46	union { struct {
 47		struct adfs_discmap *s_map;	/* bh list containing map */
 48		const struct adfs_dir_ops *s_dir; /* directory operations */
 49		};
 50		struct rcu_head rcu;	/* used only at shutdown time	 */
 51	};
 52	kuid_t		s_uid;		/* owner uid */
 53	kgid_t		s_gid;		/* owner gid */
 54	umode_t		s_owner_mask;	/* ADFS owner perm -> unix perm */
 55	umode_t		s_other_mask;	/* ADFS other perm -> unix perm	*/
 56	int		s_ftsuffix;	/* ,xyz hex filetype suffix option */
 57
 58	__u32		s_ids_per_zone;	/* max. no ids in one zone */
 59	__u32		s_idlen;	/* length of ID in map */
 60	__u32		s_map_size;	/* sector size of a map	*/
 61	unsigned long	s_size;		/* total size (in blocks) of this fs */
 62	signed int	s_map2blk;	/* shift left by this for map->sector*/
 63	unsigned int	s_log2sharesize;/* log2 share size */
 64	__le32		s_version;	/* disc format version */
 65	unsigned int	s_namelen;	/* maximum number of characters in name	 */
 66};
 67
 68static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
 69{
 70	return sb->s_fs_info;
 71}
 72
 73static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
 74{
 75	return container_of(inode, struct adfs_inode_info, vfs_inode);
 76}
 77
 78/*
 79 * Directory handling
 80 */
 81struct adfs_dir {
 82	struct super_block	*sb;
 83
 84	int			nr_buffers;
 85	struct buffer_head	*bh[4];
 86
 87	/* big directories need allocated buffers */
 88	struct buffer_head	**bh_fplus;
 89
 90	unsigned int		pos;
 91	unsigned int		parent_id;
 92
 93	struct adfs_dirheader	dirhead;
 94	union  adfs_dirtail	dirtail;
 95};
 96
 97/*
 98 * This is the overall maximum name length
 99 */
100#define ADFS_MAX_NAME_LEN	(256 + 4) /* +4 for ,xyz hex filetype suffix */
101struct object_info {
102	__u32		parent_id;		/* parent object id	*/
103	__u32		file_id;		/* object id		*/
104	__u32		loadaddr;		/* load address		*/
105	__u32		execaddr;		/* execution address	*/
106	__u32		size;			/* size			*/
107	__u8		attr;			/* RISC OS attributes	*/
108	unsigned int	name_len;		/* name length		*/
109	char		name[ADFS_MAX_NAME_LEN];/* file name		*/
110
111	/* RISC OS file type (12-bit: derived from loadaddr) */
112	__u16		filetype;
113};
114
115/* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */
116static inline int append_filetype_suffix(char *buf, __u16 filetype)
117{
118	if (filetype == 0xffff)	/* no explicit 12-bit file type was set */
119		return 0;
120
121	*buf++ = ',';
122	*buf++ = hex_asc_lo(filetype >> 8);
123	*buf++ = hex_asc_lo(filetype >> 4);
124	*buf++ = hex_asc_lo(filetype >> 0);
125	return 4;
126}
127
128struct adfs_dir_ops {
129	int	(*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
 
130	int	(*setpos)(struct adfs_dir *dir, unsigned int fpos);
131	int	(*getnext)(struct adfs_dir *dir, struct object_info *obj);
132	int	(*update)(struct adfs_dir *dir, struct object_info *obj);
133	int	(*create)(struct adfs_dir *dir, struct object_info *obj);
134	int	(*remove)(struct adfs_dir *dir, struct object_info *obj);
135	int	(*sync)(struct adfs_dir *dir);
136	void	(*free)(struct adfs_dir *dir);
137};
138
139struct adfs_discmap {
140	struct buffer_head	*dm_bh;
141	__u32			dm_startblk;
142	unsigned int		dm_startbit;
143	unsigned int		dm_endbit;
144};
145
146/* Inode stuff */
147struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
148int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
149int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
150
151/* map.c */
152extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
153extern unsigned int adfs_map_free(struct super_block *sb);
154
155/* Misc */
156__printf(3, 4)
157void __adfs_error(struct super_block *sb, const char *function,
158		  const char *fmt, ...);
159#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
 
160
161/* super.c */
162
163/*
164 * Inodes and file operations
165 */
166
167/* dir_*.c */
168extern const struct inode_operations adfs_dir_inode_operations;
169extern const struct file_operations adfs_dir_operations;
170extern const struct dentry_operations adfs_dentry_operations;
171extern const struct adfs_dir_ops adfs_f_dir_ops;
172extern const struct adfs_dir_ops adfs_fplus_dir_ops;
173
 
174extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
175			   int wait);
176
177/* file.c */
178extern const struct inode_operations adfs_file_inode_operations;
179extern const struct file_operations adfs_file_operations;
180
181static inline __u32 signed_asl(__u32 val, signed int shift)
182{
183	if (shift >= 0)
184		val <<= shift;
185	else
186		val >>= -shift;
187	return val;
188}
189
190/*
191 * Calculate the address of a block in an object given the block offset
192 * and the object identity.
193 *
194 * The root directory ID should always be looked up in the map [3.4]
195 */
196static inline int
197__adfs_block_map(struct super_block *sb, unsigned int object_id,
198		 unsigned int block)
199{
200	if (object_id & 255) {
201		unsigned int off;
202
203		off = (object_id & 255) - 1;
204		block += off << ADFS_SB(sb)->s_log2sharesize;
205	}
206
207	return adfs_map_lookup(sb, object_id >> 8, block);
 
 
 
 
 
 
 
 
 
 
 
 
 
208}