File: sync.c

package info (click to toggle)
xfsprogs 6.18.0-3
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,480 kB
  • sloc: ansic: 167,330; sh: 4,604; makefile: 1,337; python: 835; cpp: 5
file content (57 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2014 Red Hat, Inc.
 * All Rights Reserved.
 */

#include "platform_defs.h"
#include "command.h"
#include "init.h"
#include "io.h"

static cmdinfo_t sync_cmd;

static int
sync_f(
	int			argc,
	char			**argv)
{
	/* sync can't fail */
	sync();
	return 0;
}

static cmdinfo_t syncfs_cmd;

static int
syncfs_f(
	int			argc,
	char			**argv)
{
	if (syncfs(file->fd) < 0) {
		perror("syncfs");
		exitcode = 1;
	}
	return 0;
}

void
sync_init(void)
{
	sync_cmd.name = "sync";
	sync_cmd.cfunc = sync_f;
	sync_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK |
			 CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
	sync_cmd.oneline =
		_("calls sync(2) to flush all in-core filesystem state to disk");

	add_command(&sync_cmd);

	syncfs_cmd.name = "syncfs";
	syncfs_cmd.cfunc = syncfs_f;
	syncfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
	syncfs_cmd.oneline =
		_("calls syncfs(2) to flush all in-core filesystem state to disk");

	add_command(&syncfs_cmd);
}