18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/fs/hpfs/hpfs_fn.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  function headers
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci//#define DBG
118c2ecf20Sopenharmony_ci//#define DEBUG_LOCKS
128c2ecf20Sopenharmony_ci#ifdef pr_fmt
138c2ecf20Sopenharmony_ci#undef pr_fmt
148c2ecf20Sopenharmony_ci#endif
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/mutex.h>
198c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
208c2ecf20Sopenharmony_ci#include <linux/buffer_head.h>
218c2ecf20Sopenharmony_ci#include <linux/slab.h>
228c2ecf20Sopenharmony_ci#include <linux/sched/signal.h>
238c2ecf20Sopenharmony_ci#include <linux/blkdev.h>
248c2ecf20Sopenharmony_ci#include <asm/unaligned.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "hpfs.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define EIOERROR  EIO
298c2ecf20Sopenharmony_ci#define EFSERROR  EUCLEAN
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define ANODE_ALLOC_FWD	512
328c2ecf20Sopenharmony_ci#define FNODE_ALLOC_FWD	0
338c2ecf20Sopenharmony_ci#define ALLOC_FWD_MIN	16
348c2ecf20Sopenharmony_ci#define ALLOC_FWD_MAX	128
358c2ecf20Sopenharmony_ci#define ALLOC_M		1
368c2ecf20Sopenharmony_ci#define FNODE_RD_AHEAD	16
378c2ecf20Sopenharmony_ci#define ANODE_RD_AHEAD	0
388c2ecf20Sopenharmony_ci#define DNODE_RD_AHEAD	72
398c2ecf20Sopenharmony_ci#define COUNT_RD_AHEAD	62
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define FREE_DNODES_ADD	58
428c2ecf20Sopenharmony_ci#define FREE_DNODES_DEL	29
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define CHKCOND(x,y) if (!(x)) printk y
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct hpfs_inode_info {
478c2ecf20Sopenharmony_ci	loff_t mmu_private;
488c2ecf20Sopenharmony_ci	ino_t i_parent_dir;	/* (directories) gives fnode of parent dir */
498c2ecf20Sopenharmony_ci	unsigned i_dno;		/* (directories) root dnode */
508c2ecf20Sopenharmony_ci	unsigned i_dpos;	/* (directories) temp for readdir */
518c2ecf20Sopenharmony_ci	unsigned i_dsubdno;	/* (directories) temp for readdir */
528c2ecf20Sopenharmony_ci	unsigned i_file_sec;	/* (files) minimalist cache of alloc info */
538c2ecf20Sopenharmony_ci	unsigned i_disk_sec;	/* (files) minimalist cache of alloc info */
548c2ecf20Sopenharmony_ci	unsigned i_n_secs;	/* (files) minimalist cache of alloc info */
558c2ecf20Sopenharmony_ci	unsigned i_ea_size;	/* size of extended attributes */
568c2ecf20Sopenharmony_ci	unsigned i_ea_mode : 1;	/* file's permission is stored in ea */
578c2ecf20Sopenharmony_ci	unsigned i_ea_uid : 1;	/* file's uid is stored in ea */
588c2ecf20Sopenharmony_ci	unsigned i_ea_gid : 1;	/* file's gid is stored in ea */
598c2ecf20Sopenharmony_ci	unsigned i_dirty : 1;
608c2ecf20Sopenharmony_ci	loff_t **i_rddir_off;
618c2ecf20Sopenharmony_ci	struct inode vfs_inode;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct hpfs_sb_info {
658c2ecf20Sopenharmony_ci	struct mutex hpfs_mutex;	/* global hpfs lock */
668c2ecf20Sopenharmony_ci	ino_t sb_root;			/* inode number of root dir */
678c2ecf20Sopenharmony_ci	unsigned sb_fs_size;		/* file system size, sectors */
688c2ecf20Sopenharmony_ci	unsigned sb_bitmaps;		/* sector number of bitmap list */
698c2ecf20Sopenharmony_ci	unsigned sb_dirband_start;	/* directory band start sector */
708c2ecf20Sopenharmony_ci	unsigned sb_dirband_size;	/* directory band size, dnodes */
718c2ecf20Sopenharmony_ci	unsigned sb_dmap;		/* sector number of dnode bit map */
728c2ecf20Sopenharmony_ci	unsigned sb_n_free;		/* free blocks for statfs, or -1 */
738c2ecf20Sopenharmony_ci	unsigned sb_n_free_dnodes;	/* free dnodes for statfs, or -1 */
748c2ecf20Sopenharmony_ci	kuid_t sb_uid;			/* uid from mount options */
758c2ecf20Sopenharmony_ci	kgid_t sb_gid;			/* gid from mount options */
768c2ecf20Sopenharmony_ci	umode_t sb_mode;		/* mode from mount options */
778c2ecf20Sopenharmony_ci	unsigned sb_eas : 2;		/* eas: 0-ignore, 1-ro, 2-rw */
788c2ecf20Sopenharmony_ci	unsigned sb_err : 2;		/* on errs: 0-cont, 1-ro, 2-panic */
798c2ecf20Sopenharmony_ci	unsigned sb_chk : 2;		/* checks: 0-no, 1-normal, 2-strict */
808c2ecf20Sopenharmony_ci	unsigned sb_lowercase : 1;	/* downcase filenames hackery */
818c2ecf20Sopenharmony_ci	unsigned sb_was_error : 1;	/* there was an error, set dirty flag */
828c2ecf20Sopenharmony_ci	unsigned sb_chkdsk : 2;		/* chkdsk: 0-no, 1-on errs, 2-allways */
838c2ecf20Sopenharmony_ci	unsigned char *sb_cp_table;	/* code page tables: */
848c2ecf20Sopenharmony_ci					/* 	128 bytes uppercasing table & */
858c2ecf20Sopenharmony_ci					/*	128 bytes lowercasing table */
868c2ecf20Sopenharmony_ci	__le32 *sb_bmp_dir;		/* main bitmap directory */
878c2ecf20Sopenharmony_ci	unsigned sb_c_bitmap;		/* current bitmap */
888c2ecf20Sopenharmony_ci	unsigned sb_max_fwd_alloc;	/* max forwad allocation */
898c2ecf20Sopenharmony_ci	int sb_timeshift;
908c2ecf20Sopenharmony_ci	struct rcu_head rcu;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	unsigned n_hotfixes;
938c2ecf20Sopenharmony_ci	secno hotfix_from[256];
948c2ecf20Sopenharmony_ci	secno hotfix_to[256];
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* Four 512-byte buffers and the 2k block obtained by concatenating them */
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct quad_buffer_head {
1008c2ecf20Sopenharmony_ci	struct buffer_head *bh[4];
1018c2ecf20Sopenharmony_ci	void *data;
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* The b-tree down pointer from a dir entry */
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci  CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
1098c2ecf20Sopenharmony_ci  return le32_to_cpu(*(__le32 *) ((void *) de + le16_to_cpu(de->length) - 4));
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* The first dir entry in a dnode */
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci  return (void *) dnode->dirent;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* The end+1 of the dir entries */
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci  CHKCOND(le32_to_cpu(dnode->first_free)>=0x14 && le32_to_cpu(dnode->first_free)<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %x\n",(unsigned)le32_to_cpu(dnode->first_free)));
1248c2ecf20Sopenharmony_ci  return (void *) dnode + le32_to_cpu(dnode->first_free);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* The dir entry after dir entry de */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci  CHKCOND(le16_to_cpu(de->length)>=0x20 && le16_to_cpu(de->length)<0x800,("HPFS: de_next_de: de->length = %x\n",(unsigned)le16_to_cpu(de->length)));
1328c2ecf20Sopenharmony_ci  return (void *) de + le16_to_cpu(de->length);
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistatic inline struct extended_attribute *fnode_ea(struct fnode *fnode)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	return (struct extended_attribute *)((char *)fnode + le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s));
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline struct extended_attribute *fnode_end_ea(struct fnode *fnode)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return (struct extended_attribute *)((char *)fnode + le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s));
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic unsigned ea_valuelen(struct extended_attribute *ea)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	return ea->valuelen_lo + 256 * ea->valuelen_hi;
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic inline struct extended_attribute *next_ea(struct extended_attribute *ea)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + ea_valuelen(ea));
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic inline secno ea_sec(struct extended_attribute *ea)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	return le32_to_cpu(get_unaligned((__le32 *)((char *)ea + 9 + ea->namelen)));
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic inline secno ea_len(struct extended_attribute *ea)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	return le32_to_cpu(get_unaligned((__le32 *)((char *)ea + 5 + ea->namelen)));
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline char *ea_data(struct extended_attribute *ea)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	return (char *)((char *)ea + 5 + ea->namelen);
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic inline unsigned de_size(int namelen, secno down_ptr)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	return ((0x1f + namelen + 3) & ~3) + (down_ptr ? 4 : 0);
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	int a;
1788c2ecf20Sopenharmony_ci	int n;
1798c2ecf20Sopenharmony_ci	if (!dst || !src) return;
1808c2ecf20Sopenharmony_ci	a = dst->down;
1818c2ecf20Sopenharmony_ci	n = dst->not_8x3;
1828c2ecf20Sopenharmony_ci	memcpy((char *)dst + 2, (char *)src + 2, 28);
1838c2ecf20Sopenharmony_ci	dst->down = a;
1848c2ecf20Sopenharmony_ci	dst->not_8x3 = n;
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic inline unsigned tstbits(__le32 *bmp, unsigned b, unsigned n)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	int i;
1908c2ecf20Sopenharmony_ci	if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
1918c2ecf20Sopenharmony_ci	if (!((le32_to_cpu(bmp[(b & 0x3fff) >> 5]) >> (b & 0x1f)) & 1)) return 1;
1928c2ecf20Sopenharmony_ci	for (i = 1; i < n; i++)
1938c2ecf20Sopenharmony_ci		if (!((le32_to_cpu(bmp[((b+i) & 0x3fff) >> 5]) >> ((b+i) & 0x1f)) & 1))
1948c2ecf20Sopenharmony_ci			return i + 1;
1958c2ecf20Sopenharmony_ci	return 0;
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* alloc.c */
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ciint hpfs_chk_sectors(struct super_block *, secno, int, char *);
2018c2ecf20Sopenharmony_cisecno hpfs_alloc_sector(struct super_block *, secno, unsigned, int);
2028c2ecf20Sopenharmony_ciint hpfs_alloc_if_possible(struct super_block *, secno);
2038c2ecf20Sopenharmony_civoid hpfs_free_sectors(struct super_block *, secno, unsigned);
2048c2ecf20Sopenharmony_ciint hpfs_check_free_dnodes(struct super_block *, int);
2058c2ecf20Sopenharmony_civoid hpfs_free_dnode(struct super_block *, secno);
2068c2ecf20Sopenharmony_cistruct dnode *hpfs_alloc_dnode(struct super_block *, secno, dnode_secno *, struct quad_buffer_head *);
2078c2ecf20Sopenharmony_cistruct fnode *hpfs_alloc_fnode(struct super_block *, secno, fnode_secno *, struct buffer_head **);
2088c2ecf20Sopenharmony_cistruct anode *hpfs_alloc_anode(struct super_block *, secno, anode_secno *, struct buffer_head **);
2098c2ecf20Sopenharmony_ciint hpfs_trim_fs(struct super_block *, u64, u64, u64, unsigned *);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* anode.c */
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cisecno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_header *, unsigned, struct buffer_head *);
2148c2ecf20Sopenharmony_cisecno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
2158c2ecf20Sopenharmony_civoid hpfs_remove_btree(struct super_block *, struct bplus_header *);
2168c2ecf20Sopenharmony_ciint hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
2178c2ecf20Sopenharmony_ciint hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, const char *);
2188c2ecf20Sopenharmony_civoid hpfs_ea_remove(struct super_block *, secno, int, unsigned);
2198c2ecf20Sopenharmony_civoid hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
2208c2ecf20Sopenharmony_civoid hpfs_remove_fnode(struct super_block *, fnode_secno fno);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/* buffer.c */
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_cisecno hpfs_search_hotfix_map(struct super_block *s, secno sec);
2258c2ecf20Sopenharmony_ciunsigned hpfs_search_hotfix_map_for_range(struct super_block *s, secno sec, unsigned n);
2268c2ecf20Sopenharmony_civoid hpfs_prefetch_sectors(struct super_block *, unsigned, int);
2278c2ecf20Sopenharmony_civoid *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
2288c2ecf20Sopenharmony_civoid *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
2298c2ecf20Sopenharmony_civoid *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
2308c2ecf20Sopenharmony_civoid *hpfs_get_4sectors(struct super_block *, unsigned, struct quad_buffer_head *);
2318c2ecf20Sopenharmony_civoid hpfs_brelse4(struct quad_buffer_head *);
2328c2ecf20Sopenharmony_civoid hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* dentry.c */
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ciextern const struct dentry_operations hpfs_dentry_operations;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* dir.c */
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistruct dentry *hpfs_lookup(struct inode *, struct dentry *, unsigned int);
2418c2ecf20Sopenharmony_ciextern const struct file_operations hpfs_dir_ops;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/* dnode.c */
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ciint hpfs_add_pos(struct inode *, loff_t *);
2468c2ecf20Sopenharmony_civoid hpfs_del_pos(struct inode *, loff_t *);
2478c2ecf20Sopenharmony_cistruct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *,
2488c2ecf20Sopenharmony_ci				const unsigned char *, unsigned, secno);
2498c2ecf20Sopenharmony_ciint hpfs_add_dirent(struct inode *, const unsigned char *, unsigned,
2508c2ecf20Sopenharmony_ci		    struct hpfs_dirent *);
2518c2ecf20Sopenharmony_ciint hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
2528c2ecf20Sopenharmony_civoid hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
2538c2ecf20Sopenharmony_cidnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
2548c2ecf20Sopenharmony_cistruct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
2558c2ecf20Sopenharmony_cistruct hpfs_dirent *map_dirent(struct inode *, dnode_secno,
2568c2ecf20Sopenharmony_ci			       const unsigned char *, unsigned, dnode_secno *,
2578c2ecf20Sopenharmony_ci			       struct quad_buffer_head *);
2588c2ecf20Sopenharmony_civoid hpfs_remove_dtree(struct super_block *, dnode_secno);
2598c2ecf20Sopenharmony_cistruct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci/* ea.c */
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_civoid hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
2648c2ecf20Sopenharmony_ciint hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
2658c2ecf20Sopenharmony_cichar *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
2668c2ecf20Sopenharmony_civoid hpfs_set_ea(struct inode *, struct fnode *, const char *,
2678c2ecf20Sopenharmony_ci		 const char *, int);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/* file.c */
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ciint hpfs_file_fsync(struct file *, loff_t, loff_t, int);
2728c2ecf20Sopenharmony_civoid hpfs_truncate(struct inode *);
2738c2ecf20Sopenharmony_ciextern const struct file_operations hpfs_file_ops;
2748c2ecf20Sopenharmony_ciextern const struct inode_operations hpfs_file_iops;
2758c2ecf20Sopenharmony_ciextern const struct address_space_operations hpfs_aops;
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/* inode.c */
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_civoid hpfs_init_inode(struct inode *);
2808c2ecf20Sopenharmony_civoid hpfs_read_inode(struct inode *);
2818c2ecf20Sopenharmony_civoid hpfs_write_inode(struct inode *);
2828c2ecf20Sopenharmony_civoid hpfs_write_inode_nolock(struct inode *);
2838c2ecf20Sopenharmony_ciint hpfs_setattr(struct dentry *, struct iattr *);
2848c2ecf20Sopenharmony_civoid hpfs_write_if_changed(struct inode *);
2858c2ecf20Sopenharmony_civoid hpfs_evict_inode(struct inode *);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* map.c */
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci__le32 *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
2908c2ecf20Sopenharmony_ci__le32 *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
2918c2ecf20Sopenharmony_civoid hpfs_prefetch_bitmap(struct super_block *, unsigned);
2928c2ecf20Sopenharmony_ciunsigned char *hpfs_load_code_page(struct super_block *, secno);
2938c2ecf20Sopenharmony_ci__le32 *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
2948c2ecf20Sopenharmony_civoid hpfs_load_hotfix_map(struct super_block *s, struct hpfs_spare_block *spareblock);
2958c2ecf20Sopenharmony_cistruct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
2968c2ecf20Sopenharmony_cistruct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
2978c2ecf20Sopenharmony_cistruct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
2988c2ecf20Sopenharmony_cidnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci/* name.c */
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ciunsigned char hpfs_upcase(unsigned char *, unsigned char);
3038c2ecf20Sopenharmony_ciint hpfs_chk_name(const unsigned char *, unsigned *);
3048c2ecf20Sopenharmony_ciunsigned char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
3058c2ecf20Sopenharmony_ciint hpfs_compare_names(struct super_block *, const unsigned char *, unsigned,
3068c2ecf20Sopenharmony_ci		       const unsigned char *, unsigned, int);
3078c2ecf20Sopenharmony_ciint hpfs_is_name_long(const unsigned char *, unsigned);
3088c2ecf20Sopenharmony_civoid hpfs_adjust_length(const unsigned char *, unsigned *);
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci/* namei.c */
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ciextern const struct inode_operations hpfs_dir_iops;
3138c2ecf20Sopenharmony_ciextern const struct address_space_operations hpfs_symlink_aops;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistatic inline struct hpfs_inode_info *hpfs_i(struct inode *inode)
3168c2ecf20Sopenharmony_ci{
3178c2ecf20Sopenharmony_ci	return container_of(inode, struct hpfs_inode_info, vfs_inode);
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic inline struct hpfs_sb_info *hpfs_sb(struct super_block *sb)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	return sb->s_fs_info;
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci/* super.c */
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci__printf(2, 3)
3288c2ecf20Sopenharmony_civoid hpfs_error(struct super_block *, const char *, ...);
3298c2ecf20Sopenharmony_ciint hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
3308c2ecf20Sopenharmony_ciunsigned hpfs_get_free_dnodes(struct super_block *);
3318c2ecf20Sopenharmony_cilong hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg);
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/*
3348c2ecf20Sopenharmony_ci * local time (HPFS) to GMT (Unix)
3358c2ecf20Sopenharmony_ci */
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic inline time64_t local_to_gmt(struct super_block *s, time64_t t)
3388c2ecf20Sopenharmony_ci{
3398c2ecf20Sopenharmony_ci	extern struct timezone sys_tz;
3408c2ecf20Sopenharmony_ci	return t + sys_tz.tz_minuteswest * 60 + hpfs_sb(s)->sb_timeshift;
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic inline time32_t gmt_to_local(struct super_block *s, time64_t t)
3448c2ecf20Sopenharmony_ci{
3458c2ecf20Sopenharmony_ci	extern struct timezone sys_tz;
3468c2ecf20Sopenharmony_ci	return t - sys_tz.tz_minuteswest * 60 - hpfs_sb(s)->sb_timeshift;
3478c2ecf20Sopenharmony_ci}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic inline time32_t local_get_seconds(struct super_block *s)
3508c2ecf20Sopenharmony_ci{
3518c2ecf20Sopenharmony_ci	return gmt_to_local(s, ktime_get_real_seconds());
3528c2ecf20Sopenharmony_ci}
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci/*
3558c2ecf20Sopenharmony_ci * Locking:
3568c2ecf20Sopenharmony_ci *
3578c2ecf20Sopenharmony_ci * hpfs_lock() locks the whole filesystem. It must be taken
3588c2ecf20Sopenharmony_ci * on any method called by the VFS.
3598c2ecf20Sopenharmony_ci *
3608c2ecf20Sopenharmony_ci * We don't do any per-file locking anymore, it is hard to
3618c2ecf20Sopenharmony_ci * review and HPFS is not performance-sensitive anyway.
3628c2ecf20Sopenharmony_ci */
3638c2ecf20Sopenharmony_cistatic inline void hpfs_lock(struct super_block *s)
3648c2ecf20Sopenharmony_ci{
3658c2ecf20Sopenharmony_ci	struct hpfs_sb_info *sbi = hpfs_sb(s);
3668c2ecf20Sopenharmony_ci	mutex_lock(&sbi->hpfs_mutex);
3678c2ecf20Sopenharmony_ci}
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic inline void hpfs_unlock(struct super_block *s)
3708c2ecf20Sopenharmony_ci{
3718c2ecf20Sopenharmony_ci	struct hpfs_sb_info *sbi = hpfs_sb(s);
3728c2ecf20Sopenharmony_ci	mutex_unlock(&sbi->hpfs_mutex);
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cistatic inline void hpfs_lock_assert(struct super_block *s)
3768c2ecf20Sopenharmony_ci{
3778c2ecf20Sopenharmony_ci	struct hpfs_sb_info *sbi = hpfs_sb(s);
3788c2ecf20Sopenharmony_ci	WARN_ON(!mutex_is_locked(&sbi->hpfs_mutex));
3798c2ecf20Sopenharmony_ci}
380